Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Thanked 0 Times in 0 Posts

    How to display results from particular one record?

    I am sorry for such a basic questions but I am very fresh in it.

    I have a form index.php that sends data to Mysql database.
    There is another page content.php that displays most of the data but if it is too much where is a link "more...." and this goes to another file more.php

    The link is fine e.g.: http://www.domain.com/more.php?id=3 (it should display data from record id=3

    What is wrong with this code?
    PHP Code:
    <table width=90% align=center rules=none frame=box border=1 cellpadding=8 bgcolor=white>
    <td width="70%" height="20" class=header> <h1 align="left"><font face="Verdana">Company Logo</font></h1></td>
    <td width="30%" height="20" align="right"><img src="images/logo.jpg"></td>

    echo '<table width="90%" border="1" align="center" cellpadding="1" cellspacing="1">
    <td style="width:5%" align=center class=strong>Ref No:</td>
    <td style="width:25%" align=center class=strong>Employee`s name:</td>
    <td style="width:8%" align=center class=strong>Date:</td>
    <td style="width:5%" class=strong align=center>Link to a file: </td>

    $id = (int) $_GET['id'];
    $query mysql_query("SELECT * FROM entries WHERE id = $id")or die('querry error');
    $row mysql_fetch_assoc($query));

    <td><u><a href='http://abc.domaain.local/uploaded/"
    .$rows['file']."'><font color='#0000ff'>".$rows['file']."</font></u></a></td></tr>"

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 Posts
    This is wrong: while($row = mysql_fetch_assoc($query));
    A semi-colon at the end of a branch is true once and only once, and with loops its the last item of the collection (you can see it in a foreach for example). In a while, the control condition is false or null, so doing that above will assign null to $row regardless of how many records you have.

    Either remove the while loop (assuming id is PK you'll only have one record anyway) or remove the semi-colon.

    So never use a semi-colon on a branch, it will definitely come back again in the future, but now you know to look for it. Since its true once and only once, if (false); is considered true, so if you see an obvious false condition evaluating true, check that it has no semi-colon at the end of the branch.


Posting Permissions

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