Jump to content

[SOLVED] Small issue. Help!


runei

Recommended Posts

Hello. I am working on a cms and i want the user to be able to view his own unpublished article(s). The following code sort of works but I only get to view one article even though i have saved 3 or 4. Gould anyone give me some suggestions of what to do? Can i loop the table over and over again until all the all the messages have been fetched? The articles are

saved in the unpublished_topics table.

Thx

runei

 

<?php

$id = ($_GET['id']);


if ($id){



#$row = mysql_fetch_assoc($result);
$sql1 = "SELECT * FROM unpublished_topics WHERE id='".$id."'";
$result1 = mysql_query($sql1) or die (mysql_error());
if (mysql_num_rows($result1) == 0){
	echo "You have no unpublished articles";
}else{

	$row1 = mysql_fetch_assoc($result1);
	$sql2 = "SELECT * FROM forum_subcategory WHERE id='".$row1['categoryid']."'";
	$result2 = mysql_query($sql2) or die (mysql_query());
	if (mysql_num_rows($result2) == 0){
		echo "error in sql2";
	}else{

$row2 = (mysql_fetch_assoc($result2));
$sql3 = "SELECT * FROM users WHERE id ='".$row1['userid']."'";
$result3 = mysql_query($sql3) or die (mysql_error());
if (mysql_num_rows($result3) == 0){
	echo "error sql3";
}else{

if (($_SESSION['userid'] == $row1['userid'])){




echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">";
echo "<tr><td colspan=\"4\" align=\"left\"><b> Unpublished articles by user : " . userid($row1['userid'], true) ."</tr>";
echo "<tr><td>Article name :</td><td>".$row1['title']."</td></tr>";
echo "<tr><td>Date posted :</td><td>".$row1['date']."</td></tr>";
echo "<br>";
echo "<tr><td colspan=\"4\"><textarea name=\"message2\" style=\"width:600px;height:100px;"\">'".$row1['message']."'</textarea></td></tr>";

echo "</table>";


}
}
}
}


}




?>

Link to comment
https://forums.phpfreaks.com/topic/130585-solved-small-issue-help/
Share on other sites

Hope it helps!  ;)

 

<?php

$id = ($_GET['id']);


if ($id){


   
   #$row = mysql_fetch_assoc($result);
   $sql1 = "SELECT * FROM unpublished_topics WHERE id='".$id."'";
   $result1 = mysql_query($sql1) or die (mysql_error());
   if (mysql_num_rows($result1) == 0){
         echo "You have no unpublished articles";
   }else{
      
      while($row1 = mysql_fetch_assoc($result1))
  {
      $sql2 = "SELECT * FROM forum_subcategory WHERE id='".$row1['categoryid']."'";
      $result2 = mysql_query($sql2) or die (mysql_query());
	//echo data here   	
}	
      if (mysql_num_rows($result2) == 0){
         echo "error in sql2";
      }else{
      
   $row2 = (mysql_fetch_assoc($result2));
   $sql3 = "SELECT * FROM users WHERE id ='".$row1['userid']."'";
   $result3 = mysql_query($sql3) or die (mysql_error());
   if (mysql_num_rows($result3) == 0){
      echo "error sql3";
   }else{
      
   if (($_SESSION['userid'] == $row1['userid'])){
      
   
   
   //THIS WILL GO UP WHERE YOU ECHO YOUR DATA
   echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">";
   echo "<tr><td colspan=\"4\" align=\"left\"><b> Unpublished articles by user : " . userid($row1['userid'], true) ."</tr>";
   echo "<tr><td>Article name :</td><td>".$row1['title']."</td></tr>";
   echo "<tr><td>Date posted :</td><td>".$row1['date']."</td></tr>";
   echo "<br>";
   echo "<tr><td colspan=\"4\"><textarea name=\"message2\" style=\"width:600px;height:100px;"">'".$row1['message']."'</textarea></td></tr>";
   
   echo "</table>";
   //
   
   }
   }
   }
   }
   
   
}




?>

Thx but not quite there yet. I have the if $_SESSION statement equal to the $row1[userid] before the table so if the current user is the userid in the if statement then the table shows ..which it does and it matches correctly with the userid but i can only get one article to show even though there are 3 articles from that user. Im trying to work it out now..

LOL! Topic solved by myself. I got it to work with the easiest code ever. PHP is like so easy...  :P Took me three hours and the code that does it is pretty much one line LOL.

 

<?php

$id = ($_GET['id']);



if ($id){

	$sql2 = "SELECT * FROM unpublished_topics WHERE `userid`='".$_SESSION['userid']."'";
	$result2 = mysql_query($sql2) or die (mysql_error());
	if (mysql_num_rows($result2) == 0){
		echo "error in sql2";
	}else{

while ($row4 = mysql_fetch_assoc($result2)){
echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">";
echo "<tr><td colspan=\"4\" align=\"left\"><b> Unpublished articles by user : " . userid($row4['userid'], true) ."</tr>";
echo "<tr><td colspan=\"0\">Article name :</td><td>".$row4['title']."</td></tr>";
echo "<tr><td>Date posted :</td><td>".$row4['date']."</td></tr>";
echo "<br>";
echo "<tr><td colspan=\"4\"><textarea name=\"message2\" style=\"width:600px;height:100px;\">'".$row4['message']."'</textarea></td></tr>";

echo "</table>";
}
}



}




?>

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.