php - Echo results not showing
225
I have tables in one db, and one is foreign keyed to the other. My problem is that I'm trying to call up information stored in one table based on the user name which links the 2 tables stored in the other. Here is my php, mind you I'm pretty fresh on the databasing and php, so cut some slack. Here is my code:
<?php
$loaduser= $_SESSION['username'];
$loaduser_conn= @mysql_connect("DB_NAME","DB_USER","DB_PASS");
mysql_select_db("user_register") or die ("Couldn't find user database.");
$gal_result= mysql_query("SELECT shoot_name FROM images WHERE username='$loaduser'") or die (mysql_error());
while($row = mysql_fetch_assoc($gal_result,MYSQL_ASSOC))
{
foreach($results['shoot_name'] as $result)
{
echo $result['shoot_name'], '<br>';
if(mysql_num_rows($gal_result) !=1) {
die("No galleries found for this user.");
}
}
}
Answer
Solution:
You can google "PHP PDO tutorial" and find many resources. Here's one that is very clear and well written: like: https://phpdelusions.net/pdo
Here's a better example:
Answer
Solution:
$results has to be fetched before tryin to get its contents.
While trying to get its contents you were fetching $row instead of $results
You are using mysql, mysql has been deprecated try using mysqli or PDO in the future.
Try this anyway.
Answer
Solution:
Try rewriting to this untested snippet (in case you want to keep using deprecated code ;))
If you want to select from multiple tables with some reference try this query:
Like anyone i would advise you on using more up to date code. See here for more info: http://php.net/manual/de/function.mysql-query.php