paragkalra Posted December 30, 2008 Share Posted December 30, 2008 I have a MySQL database and a table containing many cool quotes. I have written small php code that fetches the data from the database and displays a random quotation on the web-browser. Everything is working but I am getting a strange error along with a random quotation: Notice: A non well formed numeric value encountered My code is: <?php include "dbconnect.php"; $query1="SELECT `srno` FROM `quotes` ORDER BY `srno` DESC LIMIT 1" ; $min=1; $maxdata=mysql_query($query1); while($maxlimit=mysql_fetch_row($maxdata)) { $max=`echo "$maxlimit[0]<br=>"`; } $quoteno=rand($min, $max); $query2 = "SELECT `quote`,`author` FROM `quotes` where `srno`=$quoteno"; $selectdata = mysql_query($query2); while($col=mysql_fetch_row($selectdata)) { echo "$col[0]<br>"; echo "- $col[1]<br>"; } ?> The exact output that being displayed with a random quote is: Notice: A non well formed numeric value encountered in /var/www/test/rquotes.php on line 13 When everything's coming your way, you're in the wrong lane. - Maxx Power Link to comment https://forums.phpfreaks.com/topic/138896-solved-notice-a-non-well-formed-numeric-value-encountered/ Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 Well what is this? $max=`echo "$maxlimit[0] "`; Have you echoed $max and $min? Link to comment https://forums.phpfreaks.com/topic/138896-solved-notice-a-non-well-formed-numeric-value-encountered/#findComment-726311 Share on other sites More sharing options...
paragkalra Posted December 30, 2008 Author Share Posted December 30, 2008 $max=`echo "$maxlimit[0]<br=>"`; Through above line I am storing the the maximum value contained in "maxlimit" into a variable called "max". That piece of code is working. Problem lies in: $quoteno=rand($min, $max); Link to comment https://forums.phpfreaks.com/topic/138896-solved-notice-a-non-well-formed-numeric-value-encountered/#findComment-726333 Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 Try this: $maxdata=mysql_query($query1) or die(mysql_error()); $maxlimit=mysql_fetch_assoc($maxdata); $max=$maxlimit['srno']; $quoteno=rand($min, $max); Link to comment https://forums.phpfreaks.com/topic/138896-solved-notice-a-non-well-formed-numeric-value-encountered/#findComment-726337 Share on other sites More sharing options...
paragkalra Posted December 30, 2008 Author Share Posted December 30, 2008 "Maq"..U r a Genious...ur code worked like a breeze.......thanks mate...... Link to comment https://forums.phpfreaks.com/topic/138896-solved-notice-a-non-well-formed-numeric-value-encountered/#findComment-726366 Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 "Maq"..U r a Genious... Far from it.... thanks mate...... You're welcome! Link to comment https://forums.phpfreaks.com/topic/138896-solved-notice-a-non-well-formed-numeric-value-encountered/#findComment-726367 Share on other sites More sharing options...
DarkWater Posted December 30, 2008 Share Posted December 30, 2008 Well what is this? $max=`echo "$maxlimit[0]<br=>"`; Have you echoed $max and $min? Did anyone else notice the fact that he was using backticks? Link to comment https://forums.phpfreaks.com/topic/138896-solved-notice-a-non-well-formed-numeric-value-encountered/#findComment-726379 Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 Well what is this? $max=`echo "$maxlimit[0] "`; Yes ---^ Link to comment https://forums.phpfreaks.com/topic/138896-solved-notice-a-non-well-formed-numeric-value-encountered/#findComment-726380 Share on other sites More sharing options...
paragkalra Posted December 30, 2008 Author Share Posted December 30, 2008 I am a newbie and it was perhaps my first php code ... Link to comment https://forums.phpfreaks.com/topic/138896-solved-notice-a-non-well-formed-numeric-value-encountered/#findComment-726388 Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 I am a newbie and it was perhaps my first php code ... Hehe, we all start somewhere. I was just asking because I've never seen that before. I though it may be something that I wasn't aware of... Link to comment https://forums.phpfreaks.com/topic/138896-solved-notice-a-non-well-formed-numeric-value-encountered/#findComment-726394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.