Jump to content

Recommended Posts

I am having a problem with my script not returning anything! I echo the variable usually it will say ARRAY and it has something in it.. Nothing at all it coming up no errors I have put or die in it, nothing. I tried error_reporting(E_ALL); , still nothing.

 

If someone can help me with this, I will greatly appreciate it.

 

~AJ :)

 


error_reporting(E_ALL);
//Get Catagorys and echo
$getCatagorys = mysql_query("SELECT * FROM `catagory`") or die("Query failed with error: ".mysql_error());
while($row = mysql_fetch_array($getCatagorys, MYSQL_ASSOC)){
echo '	<tr>
        		<td class="catagoryTD" width="550">'.$row['catagoryTitle'].'</td>
        		<td class="catagoryTD" width="75"><center>Threads</center></td>
        		<td class="catagoryTD" width="75"><center>Posts</center></td>
        		<td class="catagoryTD" width="170"><center>Last Post</center></td>
      		</tr>';

//Get SubCatagorys and echo			
$catagoryID = $row['catagoryID'];
$getSubCatagory = mysql_query("SELECT * FROM `subcatagory` where catagoryID = '$catagoryID'");
while($subrow = mysql_fetch_array($getSubCatagory, MYSQL_ASSOC)){
	$subCatagory = $subrow['subcatagoryID'];	

	//Get Stats for number of threads
	$threads = mysql_query("SELECT * FROM entry WHERE subcatagoryID = '$subCatagory'") or die(mysql_error());
	$num_threads = mysql_num_rows($threads);

	//Get Stats for number of entrys(posts)		
	$posts = mysql_query("SELECT * FROM posts WHERE subcatagoryID = '$subCatagory'") or die(mysql_error());
	$num_posts = mysql_num_rows($posts);

	//Find newest post and find what thread it is from
	$lastPost = mysql_query("SELECT * FROM `posts` ORDER BY `posts`.`postCreated` DESC") or die(mysql_error());
	while($lastPostReturn = mysql_fetch_array($getSubCatagory, MYSQL_ASSOC)){
		echo $lastPostReturn;	
	}

	//Grab User and thread number and date
	$lastPostUser = $lastPostReturn['postUser'];
	$lastPostCreated = $lastPostReturn['postCreated'];
	$lastPostEntry = $lastPostReturn['entryID'];

	//Find the title of the thread and generate URL\
	$lastPostThread = mysql_query("SELECT * FROM `entry` WHERE entryID = '$lastPostEntry'");
	while($lastPostThreadReturn = mysql_fetch_array($lastPostThread, MYSQL_ASSOC)){

	}

			echo '	<tr>
        				<td><a href="catagory.php?id='.$subrow['subcatagoryID'].'">'.$subrow['subcatagoryTitle'].'</a></td>
        				<td><center>'.$num_threads.'</center></td>
        				<td><center>'.$num_posts.'</center></td>
        				<td>'.$lastPostThreadReturn['text'].'<br>'.$lastPostCreated.'<br>'.$lastPostUser.'</td>
      				</tr>';	
							}

}

Link to comment
https://forums.phpfreaks.com/topic/213814-mysql_fetch_array-problem/
Share on other sites

This may sound stupid, but above this code you need a connection.(en close it in the end)

Are you sure you are connected to the database, because everything on this page depends on that.

And if you do have a connection, maybe try to split all the while loops up for testing. Do they work separate?

are you using <?  ?> or  <?php ?>

 

I didn't count the brackets, but if I had this long code i would have separated each pieces to have it work and after that put it together. ::)

 

So not a solution, but hopefully still something useful.

this part of your code doesn't make too much sense.... ;

 

		//Find newest post and find what thread it is from
	$lastPost = mysql_query("SELECT * FROM `posts` ORDER BY `posts`.`postCreated` DESC") or die(mysql_error());
	while($lastPostReturn = mysql_fetch_array($getSubCatagory, MYSQL_ASSOC)){
		echo $lastPostReturn;	
	}

	//Grab User and thread number and date
	$lastPostUser = $lastPostReturn['postUser'];
	$lastPostCreated = $lastPostReturn['postCreated'];
	$lastPostEntry = $lastPostReturn['entryID'];

 

seems that you want just the latest post, therefore your select should use the LIMIT 1 at the end... and also your WHILE is using the $getSubCategory instead of $lastPost... on top of that is you are retrieving only one $lastPost you don't need a WHILE loop at all... you can use just a $lastPostReturn = mysql_fetch_assoc($lastPost) for a final code like this:

 

//Find newest post and find what thread it is from
	$lastPost = mysql_query("SELECT * FROM `posts` ORDER BY `posts`.`postCreated` DESC LIMIT 1") or die(mysql_error());

	$lastPostReturn = mysql_fetch_assoc($lastPost);

	//Grab User and thread number and date
	$lastPostUser = $lastPostReturn['postUser'];
	$lastPostCreated = $lastPostReturn['postCreated'];
	$lastPostEntry = $lastPostReturn['entryID'];

 

after that part... your next  WHILE

		//Find the title of the thread and generate URL\
	$lastPostThread = mysql_query("SELECT * FROM `entry` WHERE entryID = '$lastPostEntry'");
	while($lastPostThreadReturn = mysql_fetch_array($lastPostThread, MYSQL_ASSOC)){

	}

 

is also wrong... nothing inside of the WHILE loop, therefore why use it ?... the solution is the same as before if you are recovering just 1 record....

 

hope this help

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.