Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jun 2013
    Posts
    30
    Thanks
    6
    Thanked 0 Times in 0 Posts

    mysql code displaying no record on echo

    hello guys, i am selecting records from 3 tables (2 more to come later) but when i echo the result, no error messages are displayed and no records are being retrieved. please verify the code below and let me know where i erred.

    PHP Code:
    <?php

    session_start
    ();

    include(
    'db_connect.php');

    $username $_SESSION['username'];

    $user mysql_fetch_assoc(mysql_query("select user_id from tbllogin where username = '{$username}'"));

    $sql = ("SELECT prod_id FROM tblfavourites WHERE user_id = '$user[user_id]'");

    $sql1 = ("SELECT ret_id FROM tblfav_ret WHERE user_id = '$user[user_id]'");

    $query mysql_query("
    SELECT p.prod_name, rp.prod_price, r.ret_name
    FROM tblproduct AS p
    LEFT JOIN tblretprod AS rp  ON (rp.prod_id = p.prod_id)
    LEFT JOIN tblretailer AS r ON (r.user_id = rp.user_id)
    WHERE p.prod_id IN ($sql) AND r.ret_id IN ($sql1)"
    );

    $row mysql_fetch_row($query);

    echo 
    $row['prod_name'];

    ?>

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    723
    Thanks
    20
    Thanked 84 Times in 84 Posts
    how are your usernames saved?

    have you tried where username = '$username'

    ( minus the {} )
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    hance (07-09-2013)

  • #3
    New Coder
    Join Date
    Jun 2013
    Posts
    30
    Thanks
    6
    Thanked 0 Times in 0 Posts
    that piece of code works fine, i use is mostly everywhere. i want to know if i wrote the mysql code well to and why there is no display when i echo the prod_name

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Where's your:
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    ?
    Since there is a lot of potential of error here (since you've done nothing to trap any errors), you need to enable your error reporting before you can say there is no error.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    New Coder
    Join Date
    Jun 2013
    Posts
    30
    Thanks
    6
    Thanked 0 Times in 0 Posts
    where do i insert that code? if i add die (mysql_query()) then error is on line 25
    meaning on this line
    $row = mysql_fetch_row($query);

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You add it to the start of the script.
    If you are adding or die to things, it doesn't necessarily mean there's an error. It means that the condition to trigger the or is that equivalent to false. Or die syntax can be added to a mysql_query, but not to a mysql_fetch_*() call for example.
    So now you know your problem. Use the information provided by or die(mysql_error()) on the mysql_query to troubleshoot the SQL syntax error. Could be an ambiguity error with the nested subqueries. Which does bring the question on the nested subqueries though, why not just stack on inner joins? Wouldn't that work for what you're doing?

    Edit:
    Oh, also. MySQL library is deprecated and will be removed in the future. You should be using the mysqli or pdo libraries instead.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    Why don't you store the user_id in a session variable, so you don't have to keep querying for it as the first thing in all your code?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #8
    New Coder
    Join Date
    Jun 2013
    Posts
    30
    Thanks
    6
    Thanked 0 Times in 0 Posts
    I managed to sort this out guys. Thank you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •