Jump to content

[SOLVED] why is my array empty??


mike12255

Recommended Posts

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

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.