MySQL Forums
Forum List  »  PHP

Re: Building a query to fetch an array
Posted by: Barry Galbraith
Date: September 24, 2012 10:05PM

>echo "$clli = $row['$pointcode']<br>";

Nope! pointcode here is the name of the field you return in your SELECT sql statement.
$row['pointcode'] is an element of the $row array. It turns out there is one element in that array, and it's name is 'pointcode'.

This is a real good case of confusing your variables.

DON'T DO THIS!
$pointcode = mysql_result($pointcode, 0);
The left side $pointcode is a (possibly) a string. The right side $pointcode is (possibly) a resource.

I don't think you substituted the code correctly, so here's the full code.
<?php

mysql_connect("localhost", "root", "");

$clli = mysql_real_escape_string($_POST['clli']);

if ($clli==NULL)
echo "Please enter an 11 digit CLLI code!";
else
{
$pointcode = mysql_query("SELECT pointcode FROM database1.tester1 WHERE clli='$clli'" );
// $pointcode will be false, or a resource

$pointcode_num_rows = mysql_num_rows($pointcode);

if ($pointcode_num_rows==0)
echo "CLLI code does not exist!";
else
{
while ($row = mysql_fetch_array($pointcode)) {
    echo "$clli = $row['pointcode']<br>";
    }
}

}

?>

Good luck,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
Re: Building a query to fetch an array
September 24, 2012 10:05PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.