DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   error in displaying results. (http://www.daniweb.com/forums/thread128007.html)

heels Jun 6th, 2008 4:55 am
error in displaying results.
 
hi,

this is a snippet of my codes,

<td><a href="editFunction.php?ID=<?php echo $contact['ID']; ?>">update</a></td>
after clicking "update", the ID will be passed to the editFunction.php page.

editFunction.php
<?php 
                //get variables from previous page
                $ID = $_GET['ID'];
               
               
                //sql statement to retrieve the commands
                $sql = "SELECT * FROM contacts WHERE ID LIKE '".$ID."'";
               
                //execute query
                $result = mysql_query($sql) or die (mysql_error());
               
                //display on table
                $contact = mysql_num_rows($result);  {
?>
.
......
<td width="140"><span class="style2">ID : </span></td>
    <td width="384">
          <input name="ID" type="ID" id="ID" value="<? echo $_GET['ID'] ?>" size="50" readonly />        </td>
  </tr>
  <tr>
    <td width="140"><span class="style2">First Name : </span></td>
    <td width="384">
      <input name="firstName" type="text" id="firstName" value="<? echo $contact['firstName'] ?>" size="50" />        </td>
  </tr>
</table>

<?php
                       
            }
?>
</body>
</html>
why aren't my results displaying out in the respective fields except for ID?
where do i start debugging? Thanks alot.

kkeith29 Jun 6th, 2008 5:04 am
Re: error in displaying results.
 
because contact contains the number of rows returned by the query.

change:

$contact = mysql_num_rows($result);

to

$contact = mysql_fetch_assoc($result);

gurmukh Jun 6th, 2008 5:54 am
Re: error in displaying results.
 
using this wll help you.
actually mysql_assoc is used to retrive resuts form
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo "Name :{$row['name']} <br>" .
        "Subject : {$row['subject']} <br>" .
        "Message : {$row['message']} <br><br>";
}

kkeith29 Jun 6th, 2008 6:34 am
Re: error in displaying results.
 
i don't think he needs the while loop because he is updating a specific row.

i use mysql_fetch_assoc() all the time. works perfectly. you can also use mysql_fetch_array, they complish the same thing.

sankar62 Jun 6th, 2008 10:17 am
Re: error in displaying results.
 
use mysql_fetch_array ..........
for mysql_num_rows........

heels Jun 9th, 2008 4:46 am
Re: error in displaying results.
 
ah, thanks alot. PROBLEM SOLVED :)


All times are GMT -4. The time now is 6:52 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC