Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP connecting to two tables in a while loop
    text
    copied!<p>I have a small and rather simple question I believe, however I have tried everything but I just can't figure out this syntax.</p> <p>I will start by entering this code (php): </p> <pre><code>require_once('connectvars.php'); // My database connection //Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); //Retrieve the data from the database $query = "SELECT * FROM pbclickslogin WHERE username='$username'"; $data = mysqli_query($dbc, $query); while ($info = mysqli_fetch_array( $data )) { echo $info['lol']; echo $info['lol2']; } </code></pre> <p>So I made up this example and let us say that "$info['lol'];" is a column inside a table named "pbclickslogin" and "$info['lol2'];" is a column inside a table named "pbclickssomethingelse". But I cannot connect to both databases at the same time, or can I? </p> <p>I have tried adding:</p> <pre><code>$query = "SELECT * FROM pbclickslogin, pbclickssomethingelse WHERE username='$username'"; </code></pre> <p>and this:</p> <pre><code>$query = "SELECT * FROM pbclickslogin WHERE username='$username'"; $query2 = "SELECT * FROM pbclickssomethingelse WHERE username='$username'"; $data = mysqli_query($dbc, $query, $query2); while ($info = mysqli_fetch_array( $data )) { echo $info['lol']; echo $info['lol2']; } </code></pre> <p>but as some of you experienced PHP users might know. These two things did not solve my problem. Do any of you have an idea of how I can connect to both of these databases while doing the while loop?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload