Prev: Send Mail from PHP Using SMTP Authentication
Next: Using PHP to launch more PHP scripts and use WinCache.
From: "Jacob Kruger" on 13 Apr 2010 04:36 I am trying to simply just loop through a set of records to spit out <li /> tags for the data therein, and on the same page, it's successfully running another query against the same connection - which I have also tried turning off just in case it was a problem with running two queries against the same connection (really don't think so), but it just tells me there are no records being returned, although I have tried simplifying the sql statement, pulling records from another table, etc. etc., and I really don't know what am doing wrong with this really simple bit of scripting: $qry = mysql_query("select CatName from tblCats where Id = " . $_REQUEST['id']); $arr = mysql_fetch_array($qry); echo "<h2>" . $arr['CatName'] . "</h2>"; //that part works fine $sql = "select Id, CatID, LinkName, LinkDescription, LinkURL from tblLinks where CatID = " . $_REQUEST['id'] . ";"; //the SQL statement seems to come out fine as well if I echo it out to the browser $qry = mysql_query($sql); $arr = mysql_fetch_array($qry); if ($arr.count > 0) { echo "<ul>"; while($row = mysql_fetch_array($arr)) { echo "<li>" . $row['LinkName'] . " - " . $row['LinkDescription'] . " - "; echo "<a href='" . $row['LinkURL'] . "' target='_blank'>" . $row['LinkURL'] .. "</a></li>"; } echo "</ul>"; } else { echo "no links in category"; } mysql_close($con); It permanently just keeps on deciding there are no rows to output, so I'm a bit confused at the moment. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' __________ Information from ESET NOD32 Antivirus, version of virus signature database 5023 (20100412) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com
From: Richard Quadling on 13 Apr 2010 04:57 On 13 April 2010 09:36, Jacob Kruger <jacobk(a)mailzone.co.za> wrote: > if ($arr.count > 0) Try ... if (mysql_num_rows($arr) > 0) -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling
From: "Jacob Kruger" on 13 Apr 2010 05:40 Thanks. Will try it out - think the .count is just related to $arr being sort of an array of records - and think I got it out of the PHP tutorial from w3schools.com, and it's worked on other pages. Anyway, the following does now seem to work fine: $qry = mysql_query($sql); if (mysql_num_rows($qry) > 0) { echo "<ul>"; while($row = mysql_fetch_array($qry)) { echo "<li>" . $row['LinkName'] . " - " . $row['LinkDescription'] . " - "; echo "<a href='" . $row['LinkURL'] . "' target='_blank'>" . $row['LinkURL'] . "</a></li>"; } echo "</ul>"; } Thanks again Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message ----- From: Ferenc Kovacs To: Jacob Kruger Sent: Tuesday, April 13, 2010 10:46 AM Subject: Re: [PHP-WIN] Trouble running a select query against a database, when I know the connection is working, and the data is there On Tue, Apr 13, 2010 at 10:36 AM, Jacob Kruger <jacobk(a)mailzone.co.za> wrote: I am trying to simply just loop through a set of records to spit out <li /> tags for the data therein, and on the same page, it's successfully running another query against the same connection - which I have also tried turning off just in case it was a problem with running two queries against the same connection (really don't think so), but it just tells me there are no records being returned, although I have tried simplifying the sql statement, pulling records from another table, etc. etc., and I really don't know what am doing wrong with this really simple bit of scripting: $qry = mysql_query("select CatName from tblCats where Id = " . $_REQUEST['id']); $arr = mysql_fetch_array($qry); echo "<h2>" . $arr['CatName'] . "</h2>"; //that part works fine $sql = "select Id, CatID, LinkName, LinkDescription, LinkURL from tblLinks where CatID = " . $_REQUEST['id'] . ";"; //the SQL statement seems to come out fine as well if I echo it out to the browser $qry = mysql_query($sql); $arr = mysql_fetch_array($qry); if ($arr.count > 0) where did you get that $arr.count thingie? you can count the result rows with mysql_num_rows http://www.php.net/manual/en/function.mysql-num-rows.php Tyrael __________ Information from ESET NOD32 Antivirus, version of virus signature database 5023 (20100412) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com __________ Information from ESET NOD32 Antivirus, version of virus signature database 5024 (20100413) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com
From: Richard Quadling on 13 Apr 2010 06:01 On 13 April 2010 10:40, Jacob Kruger <jacobk(a)mailzone.co.za> wrote: > Thanks. > > Will try it out - think the .count is just related to $arr being sort of an array of records - and think I got it out of the PHP tutorial from w3schools.com, and it's worked on other pages. > > Anyway, the following does now seem to work fine: > > $qry = mysql_query($sql); > if (mysql_num_rows($qry) > 0) > { > echo "<ul>"; > while($row = mysql_fetch_array($qry)) > Â { > echo "<li>" . $row['LinkName'] . " - " . $row['LinkDescription'] . " - "; > echo "<a href='" . $row['LinkURL'] . "' target='_blank'>" . $row['LinkURL'] . "</a></li>"; > Â } > echo "</ul>"; > } > > Thanks again > > Stay well > > Jacob Kruger > Blind Biker > Skype: BlindZA > '...fate had broken his body, but not his spirit...' > > Â ----- Original Message ----- > Â From: Ferenc Kovacs > Â To: Jacob Kruger > Â Sent: Tuesday, April 13, 2010 10:46 AM > Â Subject: Re: [PHP-WIN] Trouble running a select query against a database, when I know the connection is working, and the data is there > > > > > > Â On Tue, Apr 13, 2010 at 10:36 AM, Jacob Kruger <jacobk(a)mailzone.co.za> wrote: > > Â Â I am trying to simply just loop through a set of records to spit out <li /> tags for the data therein, and on the same page, it's successfully running another query against the same connection - which I have also tried turning off just in case it was a problem with running two queries against the same connection (really don't think so), but it just tells me there are no records being returned, although I have tried simplifying the sql statement, pulling records from another table, etc. etc., and I really don't know what am doing wrong with this really simple bit of scripting: > > Â Â $qry = mysql_query("select CatName from tblCats where Id = " . $_REQUEST['id']); > Â Â $arr = mysql_fetch_array($qry); > Â Â echo "<h2>" . $arr['CatName'] . "</h2>"; > Â Â //that part works fine > Â Â $sql = "select Id, CatID, LinkName, LinkDescription, LinkURL from tblLinks where CatID = " . $_REQUEST['id'] . ";"; > Â Â //the SQL statement seems to come out fine as well if I echo it out to the browser > Â Â $qry = mysql_query($sql); > Â Â $arr = mysql_fetch_array($qry); > Â Â if ($arr.count > 0) > > > Â where did you get that $arr.count thingie? > Â you can count the result rows with mysql_num_rows > Â http://www.php.net/manual/en/function.mysql-num-rows.php > > Â Tyrael > > > > > > __________ Information from ESET NOD32 Antivirus, version of virus signature database 5023 (20100412) __________ > > The message was checked by ESET NOD32 Antivirus. > > http://www.eset.com > > > > __________ Information from ESET NOD32 Antivirus, version of virus signature database 5024 (20100413) __________ > > The message was checked by ESET NOD32 Antivirus. > > http://www.eset.com > > Nope. Breakdown of $arr.count 1 - $arr 2 - . 3 - count 1 - $arr This is a variable which, in this instance, is a mysql result resource. Not usefully expressable as a string under normal conditions. 2 - . This is the append/concatentate operator. 3 - count In this state, this will try and find the value of the constant called 'count'. If it doesn't find one, it will assume the text of 'count'. So, this becomes something like ... "Resource id #5count" And when you test that "> 0", you get false. e.g. php -r "var_dump(fopen('./AUTOEXEC.BAT', 'rt').count);" outputs ... Notice: Use of undefined constant count - assumed 'count' in Command line code on line 1 string(19) "Resource id #5count" and ... php -r "var_dump(fopen('./AUTOEXEC.BAT', 'rt').count > 0);" outputs ... Notice: Use of undefined constant count - assumed 'count' in Command line code on line 1 bool(false) My error_reporting level is set to -1. If yours is set to E_ALL, then the E_NOTICES won't be seen on any version less than PHP6/trunk. So, first set the error reporting to -1 (to really show ALL messages) and re-run your code. You'll see the error. Regards, Richard. -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling
From: "Jacob Kruger" on 13 Apr 2010 06:55 Thanks - will definitely be setting errors to show all as well - in old days with classic ASP, it was around the first server settings change you implemented to test/develop things. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message ----- From: "Richard Quadling" <rquadling(a)googlemail.com> To: "Jacob Kruger" <jacobk(a)mailzone.co.za> Cc: <php-windows(a)lists.php.net> Sent: Tuesday, April 13, 2010 12:01 PM Subject: Re: [PHP-WIN] Trouble running a select query against a database, when I know the connection is working, and the data is there On 13 April 2010 10:40, Jacob Kruger <jacobk(a)mailzone.co.za> wrote: > Thanks. > > Will try it out - think the .count is just related to $arr being sort of > an array of records - and think I got it out of the PHP tutorial from > w3schools.com, and it's worked on other pages. > > Anyway, the following does now seem to work fine: > > $qry = mysql_query($sql); > if (mysql_num_rows($qry) > 0) > { > echo "<ul>"; > while($row = mysql_fetch_array($qry)) > { > echo "<li>" . $row['LinkName'] . " - " . $row['LinkDescription'] . " - "; > echo "<a href='" . $row['LinkURL'] . "' target='_blank'>" . > $row['LinkURL'] . "</a></li>"; > } > echo "</ul>"; > } > > Thanks again > > Stay well > > Jacob Kruger > Blind Biker > Skype: BlindZA > '...fate had broken his body, but not his spirit...' > > ----- Original Message ----- > From: Ferenc Kovacs > To: Jacob Kruger > Sent: Tuesday, April 13, 2010 10:46 AM > Subject: Re: [PHP-WIN] Trouble running a select query against a database, > when I know the connection is working, and the data is there > > > > > > On Tue, Apr 13, 2010 at 10:36 AM, Jacob Kruger <jacobk(a)mailzone.co.za> > wrote: > > I am trying to simply just loop through a set of records to spit out <li > /> tags for the data therein, and on the same page, it's successfully > running another query against the same connection - which I have also > tried turning off just in case it was a problem with running two queries > against the same connection (really don't think so), but it just tells me > there are no records being returned, although I have tried simplifying the > sql statement, pulling records from another table, etc. etc., and I really > don't know what am doing wrong with this really simple bit of scripting: > > $qry = mysql_query("select CatName from tblCats where Id = " . > $_REQUEST['id']); > $arr = mysql_fetch_array($qry); > echo "<h2>" . $arr['CatName'] . "</h2>"; > //that part works fine > $sql = "select Id, CatID, LinkName, LinkDescription, LinkURL from tblLinks > where CatID = " . $_REQUEST['id'] . ";"; > //the SQL statement seems to come out fine as well if I echo it out to the > browser > $qry = mysql_query($sql); > $arr = mysql_fetch_array($qry); > if ($arr.count > 0) > > > where did you get that $arr.count thingie? > you can count the result rows with mysql_num_rows > http://www.php.net/manual/en/function.mysql-num-rows.php > > Tyrael > > > > > > __________ Information from ESET NOD32 Antivirus, version of virus > signature database 5023 (20100412) __________ > > The message was checked by ESET NOD32 Antivirus. > > http://www.eset.com > > > > __________ Information from ESET NOD32 Antivirus, version of virus > signature database 5024 (20100413) __________ > > The message was checked by ESET NOD32 Antivirus. > > http://www.eset.com > > Nope. Breakdown of $arr.count 1 - $arr 2 - . 3 - count 1 - $arr This is a variable which, in this instance, is a mysql result resource. Not usefully expressable as a string under normal conditions. 2 - . This is the append/concatentate operator. 3 - count In this state, this will try and find the value of the constant called 'count'. If it doesn't find one, it will assume the text of 'count'. So, this becomes something like ... "Resource id #5count" And when you test that "> 0", you get false. e.g. php -r "var_dump(fopen('./AUTOEXEC.BAT', 'rt').count);" outputs ... Notice: Use of undefined constant count - assumed 'count' in Command line code on line 1 string(19) "Resource id #5count" and ... php -r "var_dump(fopen('./AUTOEXEC.BAT', 'rt').count > 0);" outputs ... Notice: Use of undefined constant count - assumed 'count' in Command line code on line 1 bool(false) My error_reporting level is set to -1. If yours is set to E_ALL, then the E_NOTICES won't be seen on any version less than PHP6/trunk. So, first set the error reporting to -1 (to really show ALL messages) and re-run your code. You'll see the error. Regards, Richard. -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling __________ Information from ESET NOD32 Antivirus, version of virus signature database 5024 (20100413) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com __________ Information from ESET NOD32 Antivirus, version of virus signature database 5024 (20100413) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com
|
Next
|
Last
Pages: 1 2 Prev: Send Mail from PHP Using SMTP Authentication Next: Using PHP to launch more PHP scripts and use WinCache. |