mike12255 Posted March 4, 2009 Share Posted March 4, 2009 I got the following code (will put at end) and im trying to grab some info from my database and stick it on the webpage however i get these errors: Notice: Undefined variable: title in /home/content/p/p/f/ppffffpp/html/stayner.ca/TEST/showquestion.php on line 57 Notice: Undefined variable: message in /home/content/p/p/f/ppffffpp/html/stayner.ca/TEST/showquestion.php on line 60 Im not sure why ??? anyway my code is below is somone could help - thanks. <?php $getthreads="SELECT * FROM forumtutorial_posts WHERE postid = '$page'"; $findamount = mysql_query($getthreads) or die (mysql_error()); //grab all the content while($r=mysql_fetch_array($findamount)) { //the format is $variable = $r["nameofmysqlcolumn"]; - makes it easier to call later CAUSE IM LAZY!! $answer=$r["answered"]; $title=$r['title']; $post=$r['post']; } ?> Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/ Share on other sites More sharing options...
RussellReal Posted March 4, 2009 Share Posted March 4, 2009 uhh, can you show line 57 and line 60? Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776025 Share on other sites More sharing options...
mike12255 Posted March 4, 2009 Author Share Posted March 4, 2009 57 is the first one, 60 is the last one: <td><div align="center"><strong><?=$title?></strong></div></td> </tr> <tr bgcolor="#E6E6E6"> <td height="138"><div align="center" class="style1"><?=$message?></div></td> Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776031 Share on other sites More sharing options...
RussellReal Posted March 4, 2009 Share Posted March 4, 2009 try adding: print_r($r); into the while loop, to see if you're grabbing anything. Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776035 Share on other sites More sharing options...
mike12255 Posted March 4, 2009 Author Share Posted March 4, 2009 oh nothing appeared so i guess im not getting anything...but i know that there is that table in my db Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776038 Share on other sites More sharing options...
RussellReal Posted March 4, 2009 Share Posted March 4, 2009 where do you set $page? Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776040 Share on other sites More sharing options...
mike12255 Posted March 4, 2009 Author Share Posted March 4, 2009 right at the top of the page: $page = $_GET['id']; Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776046 Share on other sites More sharing options...
RussellReal Posted March 4, 2009 Share Posted March 4, 2009 what does your table look like? show a screenie or something if possible.. Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776048 Share on other sites More sharing options...
mike12255 Posted March 4, 2009 Author Share Posted March 4, 2009 http://img21.imageshack.us/img21/4605/problemy.jpg Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776052 Share on other sites More sharing options...
RussellReal Posted March 4, 2009 Share Posted March 4, 2009 ok.. try this: <?php if (isset($_GET['page'])) { $pid = (int) $_GET['page']; if ($pid) { mysql_connect("host.to.connect.to","user","password"); mysql_select_db("dbToUse"); $q = mysql_query("SELECT * FROM `forumtutorial_posts` WHERE `postid` = '$pid' LIMIT 1"); if ($a = mysql_fetch_assoc($q)) { print_r($a); } else { // post $pid does not exist.. } } else { // $pid is not a number or a positive number. } } else { // page GET VAR not set } ?> change the values according to what you're doing Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776062 Share on other sites More sharing options...
mike12255 Posted March 4, 2009 Author Share Posted March 4, 2009 well now i get output: Array ( [postid] => 59 [answered] => 0 [area] => [author] => test [title] => test => test [showtime] => March 3, 2009, 4:06 pm [realtime] => 1236121616 [lastposter] => test [numreplies] => 0 [parentid] => 0 [lastrepliedto] => 0 [locked] => 0 ) Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776069 Share on other sites More sharing options...
sasa Posted March 4, 2009 Share Posted March 4, 2009 are this code <?php $getthreads="SELECT * FROM forumtutorial_posts WHERE postid = '$page'"; $findamount = mysql_query($getthreads) or die (mysql_error()); //grab all the content while($r=mysql_fetch_array($findamount)) { //the format is $variable = $r["nameofmysqlcolumn"]; - makes it easier to call later CAUSE IM LAZY!! $answer=$r["answered"]; $title=$r['title']; $post=$r['post']; } ?> before this one <td><div align="center"><strong><?=$title?></strong></div></td> </tr> <tr bgcolor="#E6E6E6"> <td height="138"><div align="center" class="style1"><?=$message?></div></td> Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776074 Share on other sites More sharing options...
mike12255 Posted March 4, 2009 Author Share Posted March 4, 2009 yes Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776075 Share on other sites More sharing options...
RussellReal Posted March 4, 2009 Share Posted March 4, 2009 just use the code I supplied, and mod it to work for your purpose Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776082 Share on other sites More sharing options...
mike12255 Posted March 4, 2009 Author Share Posted March 4, 2009 using your code to set vars i could do this right: if ($a = mysql_fetch_assoc($q)) { $title = $a['title']; $message = $a['post']; Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776084 Share on other sites More sharing options...
RussellReal Posted March 4, 2009 Share Posted March 4, 2009 yes sir Link to comment https://forums.phpfreaks.com/topic/147856-solved-why-is-my-array-empty/#findComment-776198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.