mysql give "1" row found, but won't display anything...

Discussion in 'PHP' started by Greenmethod, Aug 21, 2007.

  1. #1
    include("index.php");
    require_once('db_con.php');
    $call_result = mysql_query("SELECT * FROM comments WHERE Cust_No='$cust_no' AND Call_No='$call_no'") or die(mysql_error());?>
    
    
    <table border="1">
    <? while ($call_row = mysql_fetch_array($call_result)) ?>
    <tr>
    <td><img src="images/STAR50x50.jpg"> <? 
    		echo mysql_num_rows($call_result) . '<br>';
    		//$date = $call_row['Date'];
    		echo  'Original date: ' . $call_row['Date'] . '<br>';
    		echo $call_row['Type'] . '<br>';
    		//echo 'Original date: ' . $date . '<br>';
    		$strDate = date('m/d/y g:i:s a', strtotime($date));
    		echo 'Date: ' . $strDate . '<br>';
    		echo '<br>' . $call_row['Type'];
    		echo $cust_no . '<br>' . $call_no?>
    </td>
    </tr>
    </table>
    PHP:
    There is the code.. i've copied and pasted the values from the mysql database, so I don't think its something wrong with the case or anything like that.. thanks for the help!

    I am getting the cust_no and call_no by manually putting it into the url.. it seems to work though.
     
    Greenmethod, Aug 21, 2007 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Put some curly braces around the while loop, otherwise it will just loop on the next statement (which, with the way you break out of PHP there, might be nothing). Also, get into the habit of using long PHP tags (<?php / ?>) as opposed to short ones (<? / ?>).

    So, try this:
    
    include("./");
    require_once('db_con.php');
    $call_result = mysql_query("SELECT * FROM comments WHERE Cust_No='$cust_no' AND Call_No='$call_no'") or die(mysql_error());?>
    
    
    <table border="1">
    <?php while ($call_row = mysql_fetch_array($call_result)) { ?>
    <tr>
    <td><img src="images/STAR50x50.jpg"> <?php 
            echo mysql_num_rows($call_result) . '<br>';
            //$date = $call_row['Date'];
            echo  'Original date: ' . $call_row['Date'] . '<br>';
            echo $call_row['Type'] . '<br>';
            //echo 'Original date: ' . $date . '<br>';
            $strDate = date('m/d/y g:i:s a', strtotime($date));
            echo 'Date: ' . $strDate . '<br>';
            echo '<br>' . $call_row['Type'];
            echo $cust_no . '<br>' . $call_no?>
    </td>
    </tr>
    <?php } ?>
    </table>
    
    PHP:
     
    TwistMyArm, Aug 21, 2007 IP
  3. linkweb

    linkweb Peon

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Posted twice
     
    linkweb, Aug 21, 2007 IP
  4. linkweb

    linkweb Peon

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I've placed a ; after $call_no.
    
    include("./");
    require_once('db_con.php');
    $call_result = mysql_query("SELECT * FROM comments WHERE Cust_No='$cust_no' AND Call_No='$call_no'") or die(mysql_error());?>
    
    
    <table border="1">
    <?php while ($call_row = mysql_fetch_array($call_result)) { ?>
    <tr>
    <td><img src="images/STAR50x50.jpg"> <?php 
            echo mysql_num_rows($call_result) . '<br>';
            //$date = $call_row['Date'];
            echo  'Original date: ' . $call_row['Date'] . '<br>';
            echo $call_row['Type'] . '<br>';
            //echo 'Original date: ' . $date . '<br>';
            $strDate = date('m/d/y g:i:s a', strtotime($date));
            echo 'Date: ' . $strDate . '<br>';
            echo '<br>' . $call_row['Type'];
            echo $cust_no . '<br>' . $call_no; ?>
    </td>
    </tr>
    <?php } ?>
    </table>
    
    PHP:
     
    linkweb, Aug 21, 2007 IP
  5. xdimension

    xdimension Peon

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    try to use lowercase for array keys, eg. $call_row['Type'] change to $call_row['type']
     
    xdimension, Aug 21, 2007 IP
  6. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks to everyone for your help! The problem was the curly brackets!

    Is there a reason for this?
     
    Greenmethod, Aug 21, 2007 IP
  7. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Glad you got it working.

    Basically it's because support for it is defined by an option. Some people have it enabled, some don't, whereas the long tags are supported no matter what.
     
    TwistMyArm, Aug 21, 2007 IP
  8. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Furthermore, short tags are deprecated as of PHP 6.
     
    sea otter, Aug 21, 2007 IP
  9. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Great! Thanks for your help!
     
    Greenmethod, Aug 21, 2007 IP