Jump to content

drop down box questin (ken2k7, you helped me out with parts of this script)


justAnoob

Recommended Posts

Below I have a page that displays some records from mysql through a pagination setup only allowing 1 row per page. That works great. What I am also trying to do is add a drop down box with a list of records for each user so the user can pick a row out instead of hitting the next button 50 times to get to there 50th picture. I have a drop down box on the page(which i put in a separate code bracket below) The question is how would I go about having it so when the user clicks on one of the rows in the drop down box, it then shows that picture?

 

<?php
<form id="form2" name="form2" method="post" action="updatetrade.php">
        <?php
session_start();
include "connection.php";
if (isset($_GET['pageno']))
{
  $pageno = $_GET['pageno'];
}
else
{
  $pageno = 1;
}
$findit = $_SESSION['id'];
$result = mysql_query("SELECT id FROM members WHERE username = '$findit' LIMIT 1");
$e_row = mysql_fetch_assoc($result);
$query = mysql_query("SELECT count(*) FROM abcxyz WHERE user_id = " . $e_row['id']) or die(mysql_error());


$query_data = mysql_fetch_row($query);
$numrows = $query_data[0];
$rows_per_page = 1;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
$prevpage = $pageno-1;
$nextpage = $pageno+1;


if ($pageno > $lastpage)
{
  $pageno = $lastpage;
}
if ($pageno < 1)
{
  $pageno = 1;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;

$sql = mysql_query("SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return FROM abcxyz WHERE user_id = " . $e_row['id'] . " $limit");   

$_SESSION['rid_of_delete_button'] = $lastpage;
if($lastpage != 0)
{
echo "<table width='954' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>";
while ($row = mysql_fetch_array($sql))
{
echo "<tr><td width='188' height='180'><div align='center'>";

echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />';

echo "</div></td><td width='188'><div align='center'>";

if(empty($row['imgpath2'])) 
{
  echo '<div align="center"><a href="picture2.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
  if(empty($row['imgpath2']))
  {
    echo "";
  }
  else
  {
    echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" /><a href="delete_image2.php"><font color="red"> X</a>';
  }
}

echo "</div></td><td width='188'><div align='center'>";

if((empty($row['imgpath3'])) and (!empty($row['imgpath2'])))
{
  echo '<div align="center"><a href="picture3.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
  if(empty($row['imgpath3']))
   {
   echo "";
   }
   else
   {
     echo '<img src="' . $row['imgpath3'] . '" width="125" alt="" /><a href="delete_image3.php"><font color="red"> X</a>';
   }
}
echo "</div></td><td width='188'><div align='center'>";
if( (empty($row['imgpath4'])) and (!empty($row['imgpath3'])) and (!empty($row['imgpath2'])) )

{
  echo '<div align="center"><a href="picture4.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
   if(empty($row['imgpath4']))
   {
   echo "";
   }
   else
   {
     echo '<img src="' . $row['imgpath4'] . '" width="125" alt="" /><a href="delete_image4.php"><font color="red"> X</a>';
   }
}
echo "</div></td><td width='190'><div align='center'>";
if( (empty($row['imgpath5'])) and (!empty($row['imgpath4'])) and (!empty($row['imgpath3'])) and (!empty($row['imgpath2'])) )
{
  echo '<div align="center"><a href="picture5.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
   if(empty($row['imgpath5']))
   {
   echo "";
   }
   else
   {
     echo '<img src="' . $row['imgpath5'] . '" width="125" alt="" /><a href="delete_image5.php"><font color="red"> X</a>';
   }
}
echo "</div></td></tr><tr><td height='43' colspan='4'>";
echo '<strong>Item Name:</strong> <input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" />   ';

if ($pageno == 1)
{
  echo " Previous Item ";
}
else
{
  echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'> Previous </a>";
}
echo "($pageno of $lastpage)";
if ( $pageno == $lastpage )
{
  echo " Next Item ";
}
else
{
  echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'> Next </a>";
}
echo "</td><td><div align='center'>";
echo '<input type="hidden" name="id" value="' . $row['id'] . '" size="25" />';
echo "</div></td></tr><tr><td height='116' colspan='4'>";
echo '<strong>Description:</strong> <textarea name="description" cols="75" rows="5">' . $row['description'] . '</textarea>';
echo "</td><td><div align='center'>";
echo '<input type="submit" name="submit" id="submit" value="Update Item">';
echo "</div></td></tr><tr><td height='124' colspan='4'>";
echo '<strong>Seeking:</strong>       <textarea name="in_return" cols="75" rows="5">' . $row['in_return'] . '            </textarea>';
echo "</td><td><div align='center'>";
if(isset($_SESSION['updatecomplete']))
{
  unset($_SESSION['updateerror']);
  echo $_SESSION['updatecomplete'];
}
if(isset($_SESSION['updateerror']))
{
  unset($_SESSION['updatecomplete']);
  echo $_SESSION['updateerror'];
}
if(isset($_SESSION['picupload']))
{
  unset($_SESSION['updatecomplete']);
  unset($_SESSION['updateerror']);
  echo $_SESSION['picupload'];
}
echo "</div></td></tr><tr><td colspan='4'>";
echo '<input type="hidden" name="category" value="' . $row['category'] . '" size="25" />';
//echo "</td><td><div align='center'>";
//echo '';
echo "</td></tr>";

$_SESSION['move_id'] = $row['id'];
$_SESSION['move_category'] = $row['category'];
$_SESSION['path_1'] = $row['imgpath'];
$_SESSION['path_2'] = $row['imgpath2'];
$_SESSION['path_3'] = $row['imgpath3'];
$_SESSION['path_4'] = $row['imgpath4'];
$_SESSION['path_5'] = $row['imgpath5'];
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];
}
echo "</table>";
}
else
{
  echo '<div align="center">You currently have no pics.<br />Post your first pic now!</div>';
}

?>
</form>
?>

<?php
$droppy="SELECT id, item_name FROM abcxyz WHERE user_id = " . $e_row['id'] . "";
$catch = mysql_query($droppy);
echo "<select name=student value=''>xxxxx</option>";
while($xxx=mysql_fetch_array($catch))
{
   echo "<option value=$xxx[id]>$xxx[item_name]</option>";
}
echo "</select>";
?>

 

And yes,, I use a lot of sessions.

     

Link to comment
Share on other sites

<?php
session_start();
include "connection.php";
echo '<form id="form2" name="form2" method="post" action="updatetrade.php">';

/*Lol loving the nested PHP tags but that wont work =( and you cant output anything to the screen before session_start(); */

if (isset($_GET['pageno']))
{
  $pageno = $_GET['pageno'];
}
else
{
  $pageno = 1;
}
$findit = $_SESSION['id'];
$result = mysql_query("SELECT id FROM members WHERE username = '$findit' LIMIT 1");
$e_row = mysql_fetch_assoc($result);
$query = mysql_query("SELECT count(*) FROM abcxyz WHERE user_id = " . $e_row['id']) or die(mysql_error());


$query_data = mysql_fetch_row($query);
$numrows = $query_data[0];
$rows_per_page = 1;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
$prevpage = $pageno-1;
$nextpage = $pageno+1;


if ($pageno > $lastpage)
{
  $pageno = $lastpage;
}
if ($pageno < 1)
{
  $pageno = 1;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;

$sql = mysql_query("SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return FROM abcxyz WHERE user_id = " . $e_row['id'] . " $limit");   

$_SESSION['rid_of_delete_button'] = $lastpage;
if($lastpage != 0)
{
echo "<table width='954' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>";
while ($row = mysql_fetch_array($sql))
{
echo "<tr><td width='188' height='180'><div align='center'>";

echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />';

echo "</div></td><td width='188'><div align='center'>";

if(empty($row['imgpath2'])) 
{
  echo '<div align="center"><a href="picture2.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
  if(empty($row['imgpath2']))
  {
    echo "";
  }
  else
  {
    echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" /><a href="delete_image2.php"><font color="red"> X</a>';
  }
}

echo "</div></td><td width='188'><div align='center'>";

if((empty($row['imgpath3'])) and (!empty($row['imgpath2'])))
{
  echo '<div align="center"><a href="picture3.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
  if(empty($row['imgpath3']))
   {
   echo "";
   }
   else
   {
     echo '<img src="' . $row['imgpath3'] . '" width="125" alt="" /><a href="delete_image3.php"><font color="red"> X</a>';
   }
}
echo "</div></td><td width='188'><div align='center'>";
if( (empty($row['imgpath4'])) and (!empty($row['imgpath3'])) and (!empty($row['imgpath2'])) )

{
  echo '<div align="center"><a href="picture4.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
   if(empty($row['imgpath4']))
   {
   echo "";
   }
   else
   {
     echo '<img src="' . $row['imgpath4'] . '" width="125" alt="" /><a href="delete_image4.php"><font color="red"> X</a>';
   }
}
echo "</div></td><td width='190'><div align='center'>";
if( (empty($row['imgpath5'])) and (!empty($row['imgpath4'])) and (!empty($row['imgpath3'])) and (!empty($row['imgpath2'])) )
{
  echo '<div align="center"><a href="picture5.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
   if(empty($row['imgpath5']))
   {
   echo "";
   }
   else
   {
     echo '<img src="' . $row['imgpath5'] . '" width="125" alt="" /><a href="delete_image5.php"><font color="red"> X</a>';
   }
}
echo "</div></td></tr><tr><td height='43' colspan='4'>";
echo '<strong>Item Name:</strong> <input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" />   ';

if ($pageno == 1)
{
  echo " Previous Item ";
}
else
{
  echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'> Previous </a>";
}
echo "($pageno of $lastpage)";
if ( $pageno == $lastpage )
{
  echo " Next Item ";
}
else
{
  echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'> Next </a>";
}
echo "</td><td><div align='center'>";
echo '<input type="hidden" name="id" value="' . $row['id'] . '" size="25" />';
echo "</div></td></tr><tr><td height='116' colspan='4'>";
echo '<strong>Description:</strong> <textarea name="description" cols="75" rows="5">' . $row['description'] . '</textarea>';
echo "</td><td><div align='center'>";
echo '<input type="submit" name="submit" id="submit" value="Update Item">';
echo "</div></td></tr><tr><td height='124' colspan='4'>";
echo '<strong>Seeking:</strong>       <textarea name="in_return" cols="75" rows="5">' . $row['in_return'] . '            </textarea>';
echo "</td><td><div align='center'>";
if(isset($_SESSION['updatecomplete']))
{
  unset($_SESSION['updateerror']);
  echo $_SESSION['updatecomplete'];
}
if(isset($_SESSION['updateerror']))
{
  unset($_SESSION['updatecomplete']);
  echo $_SESSION['updateerror'];
}
if(isset($_SESSION['picupload']))
{
  unset($_SESSION['updatecomplete']);
  unset($_SESSION['updateerror']);
  echo $_SESSION['picupload'];
}
echo "</div></td></tr><tr><td colspan='4'>";
echo '<input type="hidden" name="category" value="' . $row['category'] . '" size="25" />';
//echo "</td><td><div align='center'>";
//echo '';
echo "</td></tr>";

$_SESSION['move_id'] = $row['id'];
$_SESSION['move_category'] = $row['category'];
$_SESSION['path_1'] = $row['imgpath'];
$_SESSION['path_2'] = $row['imgpath2'];
$_SESSION['path_3'] = $row['imgpath3'];
$_SESSION['path_4'] = $row['imgpath4'];
$_SESSION['path_5'] = $row['imgpath5'];
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];
}
echo "</table>";
}
else
{
  echo '<div align="center">You currently have no pics.<br />Post your first pic now!</div>';
}

?>
</form>

Link to comment
Share on other sites

<?php
session_start();
//etc.

if ( isSet($_POST['selec']) )
{
   if ( !empty($_POST['options']) )
   {
   $first = true;
      forEach($options as $queVal)
      {
         if ( isSet($first) )
         {
            $buildQue = ' AND id = ' . intVal($queVal) . ' ';
            $first = false;
         }else{
         $buildQue .= 'OR id = ' . intVal($queVal) . ' ';
         }
      }
   }
}

//etc...

$sql = mysql_query("SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return FROM abcxyz WHERE user_id = " . $e_row['id'] . " " . $buildQue . " $limit");

 

<form method="post" action="">
   <select name="options[]" multiple="multiple">
<?php
$droppy = "SELECT id, item_name FROM abcxyz WHERE user_id = " . $e_row['id'] . "";
$xxx    = mysql_query($droppy)or trigger_error(mysql_error());
   while ( $row = mysql_fetch_row($xxx) )
   {
      echo '
      <option value=' . $row[0] . '>' . $row[1] . '</option>';
   }
?>
   </select><input type="submit" name="selec" value="Show Selected" >
</form>

 

Try that..

Link to comment
Share on other sites

Sorry for the misunderstanding.. my drop down box is inside a form already(which already has an action) And I can't put the drop down box outside the form because that is where all my data is displayed. I'm getting tired... Here is the whole script with a commented spot where I would like to put the drop down box at.. Again, sorry for the confusion. If you any spare time, could you please take anothe look. Oh yeh,, I would still like to keep the pagination in case the user just wants to browse his/her pics. Just want the drop down box there so they can go straight to a picture. Thanks.

        <?php
session_start();
include "connection.php";
if (isset($_GET['pageno']))
{
  $pageno = $_GET['pageno'];
}
else
{
  $pageno = 1;
}
$findit = $_SESSION['id'];
$result = mysql_query("SELECT id FROM members WHERE username = '$findit' LIMIT 1");
$e_row = mysql_fetch_assoc($result);
$query = mysql_query("SELECT count(*) FROM abcxyz WHERE user_id = " . $e_row['id']) or die(mysql_error());


$query_data = mysql_fetch_row($query);
$numrows = $query_data[0];
$rows_per_page = 1;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
$prevpage = $pageno-1;
$nextpage = $pageno+1;


if ($pageno > $lastpage)
{
  $pageno = $lastpage;
}
if ($pageno < 1)
{
  $pageno = 1;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;

$sql = mysql_query("SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return FROM abcxyz WHERE user_id = " . $e_row['id'] . " $limit");   

$_SESSION['rid_of_delete_button'] = $lastpage;
if($lastpage != 0)
{
echo "<table width='954' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>";
while ($row = mysql_fetch_array($sql))
{
echo "<tr><td width='188' height='180'><div align='center'>";

echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />';

echo "</div></td><td width='188'><div align='center'>";

if(empty($row['imgpath2'])) 
{
  echo '<div align="center"><a href="picture2.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
  if(empty($row['imgpath2']))
  {
    echo "";
  }
  else
  {
    echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" /><a href="delete_image2.php"><font color="red"> X</a>';
  }
}

echo "</div></td><td width='188'><div align='center'>";

if((empty($row['imgpath3'])) and (!empty($row['imgpath2'])))
{
  echo '<div align="center"><a href="picture3.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
  if(empty($row['imgpath3']))
   {
   echo "";
   }
   else
   {
     echo '<img src="' . $row['imgpath3'] . '" width="125" alt="" /><a href="delete_image3.php"><font color="red"> X</a>';
   }
}
echo "</div></td><td width='188'><div align='center'>";
if( (empty($row['imgpath4'])) and (!empty($row['imgpath3'])) and (!empty($row['imgpath2'])) )

{
  echo '<div align="center"><a href="picture4.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
   if(empty($row['imgpath4']))
   {
   echo "";
   }
   else
   {
     echo '<img src="' . $row['imgpath4'] . '" width="125" alt="" /><a href="delete_image4.php"><font color="red"> X</a>';
   }
}
echo "</div></td><td width='190'><div align='center'>";
if( (empty($row['imgpath5'])) and (!empty($row['imgpath4'])) and (!empty($row['imgpath3'])) and (!empty($row['imgpath2'])) )
{
  echo '<div align="center"><a href="picture5.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
   if(empty($row['imgpath5']))
   {
   echo "";
   }
   else
   {
     echo '<img src="' . $row['imgpath5'] . '" width="125" alt="" /><a href="delete_image5.php"><font color="red"> X</a>';
   }
}
echo "</div></td></tr><tr><td height='43' colspan='4'>";
echo '<strong>Item Name:</strong> <input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" />   ';

if ($pageno == 1)
{
  echo " Previous Item ";
}
else
{
  echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'> Previous </a>";
}
echo "($pageno of $lastpage)";
if ( $pageno == $lastpage )
{
  echo " Next Item ";
}
else
{
  echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'> Next </a>";
}

/////////////////////////////////////////////  Drop down box here  //////////////////////////////

echo "</td><td><div align='center'>";
echo '<input type="hidden" name="id" value="' . $row['id'] . '" size="25" />';
echo "</div></td></tr><tr><td height='116' colspan='4'>";
echo '<strong>Description:</strong> <textarea name="description" cols="75" rows="5">' . $row['description'] . '</textarea>';
echo "</td><td><div align='center'>";
echo '<input type="submit" name="submit" id="submit" value="Update Item">';
echo "</div></td></tr><tr><td height='124' colspan='4'>";
echo '<strong>Seeking:</strong>       <textarea name="in_return" cols="75" rows="5">' . $row['in_return'] . '            </textarea>';
echo "</td><td><div align='center'>";
if(isset($_SESSION['updatecomplete']))
{
  unset($_SESSION['updateerror']);
  echo $_SESSION['updatecomplete'];
}
if(isset($_SESSION['updateerror']))
{
  unset($_SESSION['updatecomplete']);
  echo $_SESSION['updateerror'];
}
if(isset($_SESSION['picupload']))
{
  unset($_SESSION['updatecomplete']);
  unset($_SESSION['updateerror']);
  echo $_SESSION['picupload'];
}
echo "</div></td></tr><tr><td colspan='4'>";
echo '<input type="hidden" name="category" value="' . $row['category'] . '" size="25" />';
//echo "</td><td><div align='center'>";
//echo '';
echo "</td></tr>";

$_SESSION['move_id'] = $row['id'];
$_SESSION['move_category'] = $row['category'];
$_SESSION['path_1'] = $row['imgpath'];
$_SESSION['path_2'] = $row['imgpath2'];
$_SESSION['path_3'] = $row['imgpath3'];
$_SESSION['path_4'] = $row['imgpath4'];
$_SESSION['path_5'] = $row['imgpath5'];
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];
}
echo "</table>";
}
else
{
  echo '<div align="center">You currently have no pictures.<br />Post your first item now!</div>';
}

?>
      </form>

Link to comment
Share on other sites

Ugh... that code is a nightmare.

 

Cleaned it up and added the drop-down. This should work.

<?php
session_start();
include "connection.php";
echo '<form id="form2" name="form2" method="get" action="updatetrade.php">';

/*Lol loving the nested PHP tags but that wont work =( and you cant output anything to the screen before session_start(); */
$pageno = isset($_GET['pageno'])? intval($_GET['pageno']) : 1;

$findit = intval($_SESSION['id']);
$result = mysql_query('SELECT m.id, COUNT(*) AS count FROM abcxyz a INNER JOIN members m ON m.id = a.user_id WHERE m.username="' . $findit .'" LIMIT 1') or trigger_error('User not found.', E_USER_ERROR);
$member_info = mysql_fetch_row($result);

$member_id = $member_info[0];
$numrows = $member_info[1];
$rows_per_page = 1;

$_SESSION['rid_of_delete_button'] = $lastpage = ceil($numrows/$rows_per_page);
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];

$prevpage = $pageno-1;
$nextpage = $pageno+1;

if ($pageno > $lastpage) $pageno = $lastpage;
else if ($pageno < 1) $pageno = 1;

$limit = 'LIMIT '. (($pageno - 1) * $rows_per_page) . ',' . $rows_per_page;

$sql = <<<QUERY
SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return
FROM abcxyz
WHERE user_id = $member_id
$limit
QUERY;

$result = mysql_query($sql) or trigger_error('Select SQL failed.', E_USER_ERROR);

if ($lastpage === 0) {
echo '<div align="center">You currently have no pics.<br />Post your first pic now!</div>';
exit;
}
?>

<table width='954' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>

<?php
// $dropdown[img_id] = img_name
$dropdown = array();

// for performance sake, just run another query even though $sql already selects the data we want.
// this will be faster than for PHP to do.
$dropdown_sql = 'SELECT id, item_name FROM abcxyz WHERE user_id = ' . $member_id;
$dropdown_result = mysql_query($dropdown_sql) or trigger_error('Select SQL failed.', E_USER_ERROR);
$dropdown_menu = '<select name="pageno">';
while ($row = mysql_fetch_assoc($dropdown_result)) {
$dropdown_menu .= '<option value="' . $row['id'] . '">' . $row['item_name'] . '</option>';
}

while ($row = mysql_fetch_assoc($sql)) {

$dropdown[$row['id']] = $row['item_name'];

echo '<tr>';
for ($e = 2; $e < 6; $e++) {
	echo '<td width="188" height="180"><div align="center"><img src="' . $row['imgpath'] . '" width="125" alt="image 1" /></div></td><td width="188"><div align="center">';
	echo empty($row['imgpath' . $e])? 
		'<a href="picure2.php"><img src="images/uploadanother.png" border="0"></a>' : 
		'<img src="' . $row['imgpath' . $e] . '" width="125" alt="" /><a href="delete_image' . $e . '.php"><span style="color: red;"> X</span></a>';
	echo '</div></td>';
}

echo '</tr><tr><td height="43" colspan="4"><strong>Item Name:</strong><input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" />  &nbsp';
echo $pageno == 1? ' Previous Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $prevpage . '"> Previous </a>(' . $pageno . ' of ' . $lastpage . ')';
echo $pageno == $lastpage? ' Next Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $nextpage . '"> Next </a>';

?>

</td>
<td><div align="center"><input type="hidden" name="id" value="<?php echo $row['id']; ?>" size="25" /></div></td>
</tr>
<tr>
	<td height="116" colspan="4"><strong>Description:</strong> <textarea name="description" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
 	<td><div align="center"><input type="submit" name="submit" id="submit" value="Update Item"></div></td>
</tr>
<tr>
	<td height="124" colspan="4"><strong>Seeking:</strong>       <textarea name="in_return" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
	<td><div align="center">';

<?php
if(isset($_SESSION['updatecomplete'])) {
	unset($_SESSION['updateerror']);
	echo $_SESSION['updatecomplete'];
}
if(isset($_SESSION['updateerror'])) {
	unset($_SESSION['updatecomplete']);
	echo $_SESSION['updateerror'];
}
if(isset($_SESSION['picupload'])) {
	unset($_SESSION['updatecomplete']);
	unset($_SESSION['updateerror']);
	echo $_SESSION['picupload'];
}
?>
	</div><td>
</tr>
<tr>
	<td colspan="4"><input type="hidden" name="category" value="<?php echo $row['category']; ?>" size="25" /></td>
</tr>
</table>
</form>
<?php
}

// doesn't matter if these are outside of the while loop
// the way they were defined, it would have the same effect.
$_SESSION['move_id'] = $row['id'];
$_SESSION['move_category'] = $row['category'];
$_SESSION['path_1'] = $row['imgpath'];
$_SESSION['path_2'] = $row['imgpath2'];
$_SESSION['path_3'] = $row['imgpath3'];
$_SESSION['path_4'] = $row['imgpath4'];
$_SESSION['path_5'] = $row['imgpath5'];

Link to comment
Share on other sites

errors happen right around here, Is that really considered cleaned up.. To me it seems more confusing.

$sql = <<<QUERY
SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return
FROM abcxyz
WHERE user_id = $member_id
$limit
QUERY;

$result = mysql_query($sql) or trigger_error('Select SQL failed.', E_USER_ERROR);

Link to comment
Share on other sites

What exactly is the error?

 

<?php
session_start();
include "connection.php";
echo '<form id="form2" name="form2" method="get" action="updatetrade.php">';

/*Lol loving the nested PHP tags but that wont work =( and you cant output anything to the screen before session_start(); */
$pageno = isset($_GET['pageno'])? intval($_GET['pageno']) : 1;

$findit = intval($_SESSION['id']);
$result = mysql_query('SELECT m.id, COUNT(*) AS count FROM abcxyz a INNER JOIN members m ON m.id = a.user_id WHERE m.username="' . $findit .'" LIMIT 1') or trigger_error('User not found.', E_USER_ERROR);
$member_info = mysql_fetch_row($result);

$member_id = intval($member_info[0]);
$numrows = intval($member_info[1]);
$rows_per_page = 1;

$_SESSION['rid_of_delete_button'] = $lastpage = ceil($numrows/$rows_per_page);
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];

$prevpage = $pageno-1;
$nextpage = $pageno+1;

if ($pageno > $lastpage) $pageno = $lastpage;
else if ($pageno < 1) $pageno = 1;

$limit = 'LIMIT '. (($pageno - 1) * $rows_per_page) . ',' . $rows_per_page;

$sql = <<<QUERY
SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return
FROM abcxyz
WHERE user_id = $member_id
$limit;
QUERY;

$result = mysql_query($sql) or trigger_error('Select SQL failed - ' . mysql_error(), E_USER_ERROR);

if ($lastpage === 0) {
   echo '<div align="center">You currently have no pics.<br />Post your first pic now!</div>';
   exit;
}
?>

<table width='954' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>

<?php
// $dropdown[img_id] = img_name
$dropdown = array();

// for performance sake, just run another query even though $sql already selects the data we want.
// this will be faster than for PHP to do.
$dropdown_sql = 'SELECT id, item_name FROM abcxyz WHERE user_id = ' . $member_id;
$dropdown_result = mysql_query($dropdown_sql) or trigger_error('Select SQL failed.', E_USER_ERROR);
$dropdown_menu = '<select name="pageno">';
while ($row = mysql_fetch_assoc($dropdown_result)) {
   $dropdown_menu .= '<option value="' . $row['id'] . '">' . $row['item_name'] . '</option>';
}

while ($row = mysql_fetch_assoc($sql)) {

   $dropdown[$row['id']] = $row['item_name'];

   echo '<tr>';
   for ($e = 2; $e < 6; $e++) {
      echo '<td width="188" height="180"><div align="center"><img src="' . $row['imgpath'] . '" width="125" alt="image 1" /></div></td><td width="188"><div align="center">';
      echo empty($row['imgpath' . $e])? 
         '<a href="picure2.php"><img src="images/uploadanother.png" border="0"></a>' : 
         '<img src="' . $row['imgpath' . $e] . '" width="125" alt="" /><a href="delete_image' . $e . '.php"><span style="color: red;"> X</span></a>';
      echo '</div></td>';
   }

   echo '</tr><tr><td height="43" colspan="4"><strong>Item Name:</strong><input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" />  &nbsp';
   echo $pageno == 1? ' Previous Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $prevpage . '"> Previous </a>(' . $pageno . ' of ' . $lastpage . ')';
   echo $pageno == $lastpage? ' Next Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $nextpage . '"> Next </a>';
   
   ?>
   
   </td>
   <td><div align="center"><input type="hidden" name="id" value="<?php echo $row['id']; ?>" size="25" /></div></td>
   </tr>
   <tr>
      <td height="116" colspan="4"><strong>Description:</strong> <textarea name="description" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
       <td><div align="center"><input type="submit" name="submit" id="submit" value="Update Item"></div></td>
   </tr>
   <tr>
      <td height="124" colspan="4"><strong>Seeking:</strong>       <textarea name="in_return" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
      <td><div align="center">';
   
   <?php
   if(isset($_SESSION['updatecomplete'])) {
      unset($_SESSION['updateerror']);
      echo $_SESSION['updatecomplete'];
   }
   if(isset($_SESSION['updateerror'])) {
      unset($_SESSION['updatecomplete']);
      echo $_SESSION['updateerror'];
   }
   if(isset($_SESSION['picupload'])) {
      unset($_SESSION['updatecomplete']);
      unset($_SESSION['updateerror']);
      echo $_SESSION['picupload'];
   }
   ?>
      </div><td>
   </tr>
   <tr>
      <td colspan="4"><input type="hidden" name="category" value="<?php echo $row['category']; ?>" size="25" /></td>
   </tr>
   </table>
</form>
   <?php
}

// doesn't matter if these are outside of the while loop
// the way they were defined, it would have the same effect.
$_SESSION['move_id'] = $row['id'];
$_SESSION['move_category'] = $row['category'];
$_SESSION['path_1'] = $row['imgpath'];
$_SESSION['path_2'] = $row['imgpath2'];
$_SESSION['path_3'] = $row['imgpath3'];
$_SESSION['path_4'] = $row['imgpath4'];
$_SESSION['path_5'] = $row['imgpath5'];

Link to comment
Share on other sites

<?php
session_start();
include "connection.php";
echo '<form id="form2" name="form2" method="get" action="updatetrade.php">';

/*Lol loving the nested PHP tags but that wont work =( and you cant output anything to the screen before session_start(); */
$pageno = isset($_GET['pageno'])? intval($_GET['pageno']) : 1;

$findit = intval($_SESSION['id']);
$result = mysql_query('SELECT m.id, COUNT(*) AS count FROM abcxyz a INNER JOIN members m ON m.id = a.user_id WHERE m.username="' . $findit .'" LIMIT 1') or trigger_error('User not found.', E_USER_ERROR);
$member_info = mysql_fetch_row($result);

$member_id = intval($member_info[0]);
$numrows = intval($member_info[1]);
$rows_per_page = 1;

$_SESSION['rid_of_delete_button'] = $lastpage = ceil($numrows/$rows_per_page);
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];

$prevpage = $pageno-1;
$nextpage = $pageno+1;

if ($pageno > $lastpage) $pageno = $lastpage;
else if ($pageno < 1) $pageno = 1;

$limit = 'LIMIT '. ($pageno * $rows_per_page) . ',' . $rows_per_page;

$sql = <<<QUERY
SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return
FROM abcxyz
WHERE user_id = $member_id
$limit;
QUERY;

$result = mysql_query($sql) or trigger_error('Select SQL failed - ' . mysql_error(), E_USER_ERROR);

if ($lastpage === 0) {
   echo '<div align="center">You currently have no pics.<br />Post your first pic now!</div>';
   exit;
}
?>

<table width='954' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>

<?php
// $dropdown[img_id] = img_name
$dropdown = array();

// for performance sake, just run another query even though $sql already selects the data we want.
// this will be faster than for PHP to do.
$dropdown_sql = 'SELECT id, item_name FROM abcxyz WHERE user_id = ' . $member_id;
$dropdown_result = mysql_query($dropdown_sql) or trigger_error('Select SQL failed.', E_USER_ERROR);
$dropdown_menu = '<select name="pageno">';
while ($row = mysql_fetch_assoc($dropdown_result)) {
   $dropdown_menu .= '<option value="' . $row['id'] . '">' . $row['item_name'] . '</option>';
}

while ($row = mysql_fetch_assoc($sql)) {

   $dropdown[$row['id']] = $row['item_name'];

   echo '<tr>';
   for ($e = 2; $e < 6; $e++) {
      echo '<td width="188" height="180"><div align="center"><img src="' . $row['imgpath'] . '" width="125" alt="image 1" /></div></td><td width="188"><div align="center">';
      echo empty($row['imgpath' . $e])? 
         '<a href="picure2.php"><img src="images/uploadanother.png" border="0"></a>' : 
         '<img src="' . $row['imgpath' . $e] . '" width="125" alt="" /><a href="delete_image' . $e . '.php"><span style="color: red;"> X</span></a>';
      echo '</div></td>';
   }

   echo '</tr><tr><td height="43" colspan="4"><strong>Item Name:</strong><input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" />  &nbsp';
   echo $pageno == 1? ' Previous Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $prevpage . '"> Previous </a>(' . $pageno . ' of ' . $lastpage . ')';
   echo $pageno == $lastpage? ' Next Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $nextpage . '"> Next </a>';
   
   ?>
   
   </td>
   <td><div align="center"><input type="hidden" name="id" value="<?php echo $row['id']; ?>" size="25" /></div></td>
   </tr>
   <tr>
      <td height="116" colspan="4"><strong>Description:</strong> <textarea name="description" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
       <td><div align="center"><input type="submit" name="submit" id="submit" value="Update Item"></div></td>
   </tr>
   <tr>
      <td height="124" colspan="4"><strong>Seeking:</strong>       <textarea name="in_return" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
      <td><div align="center">';
   
   <?php
   if(isset($_SESSION['updatecomplete'])) {
      unset($_SESSION['updateerror']);
      echo $_SESSION['updatecomplete'];
   }
   if(isset($_SESSION['updateerror'])) {
      unset($_SESSION['updatecomplete']);
      echo $_SESSION['updateerror'];
   }
   if(isset($_SESSION['picupload'])) {
      unset($_SESSION['updatecomplete']);
      unset($_SESSION['updateerror']);
      echo $_SESSION['picupload'];
   }
   ?>
      </div><td>
   </tr>
   <tr>
      <td colspan="4"><input type="hidden" name="category" value="<?php echo $row['category']; ?>" size="25" /></td>
   </tr>
   </table>
</form>
   <?php
}

// doesn't matter if these are outside of the while loop
// the way they were defined, it would have the same effect.
$_SESSION['move_id'] = $row['id'];
$_SESSION['move_category'] = $row['category'];
$_SESSION['path_1'] = $row['imgpath'];
$_SESSION['path_2'] = $row['imgpath2'];
$_SESSION['path_3'] = $row['imgpath3'];
$_SESSION['path_4'] = $row['imgpath4'];
$_SESSION['path_5'] = $row['imgpath5'];

Link to comment
Share on other sites

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource on line 238

the commented line below......

<?php
$dropdown_sql = 'SELECT id, item_name FROM abcxyz WHERE user_id = ' . $member_id;
$dropdown_result = mysql_query($dropdown_sql) or trigger_error('Select SQL failed.', E_USER_ERROR);
$dropdown_menu = '<select name="pageno">';
while ($row = mysql_fetch_assoc($dropdown_result)) {
   $dropdown_menu .= '<option value="' . $row['id'] . '">' . $row['item_name'] . '</option>';
}

while ($row = mysql_fetch_assoc($sql))     ////this one
?>

Link to comment
Share on other sites

Here is everything from the script to the end of the page

<form id="form2" name="form2" method="post" action="updatetrade.php">
        <?php
session_start();
include "connection.php";
echo '<form id="form2" name="form2" method="get" action="updatetrade.php">';

$pageno = isset($_GET['pageno'])? intval($_GET['pageno']) : 1;

$findit = intval($_SESSION['id']);
$result = mysql_query('SELECT m.id, COUNT(*) AS count FROM abcxyz a INNER JOIN members m ON m.id = a.user_id WHERE m.username="' . $findit .'" LIMIT 1') or trigger_error('User not found.', E_USER_ERROR);
$member_info = mysql_fetch_row($result);

$member_id = intval($member_info[0]);
$numrows = intval($member_info[1]);
$rows_per_page = 1;

$_SESSION['rid_of_delete_button'] = $lastpage = ceil($numrows/$rows_per_page);
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];

$prevpage = $pageno-1;
$nextpage = $pageno+1;

if ($pageno > $lastpage) $pageno = $lastpage;
else if ($pageno < 1) $pageno = 1;

$limit = 'LIMIT '. ($pageno * $rows_per_page) . ',' . $rows_per_page;

$sql = <<<QUERY
SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return
FROM abcxyz
WHERE user_id = $member_id
$limit;
QUERY;

$result = mysql_query($sql) or trigger_error('Select SQL failed - ' . mysql_error(), E_USER_ERROR);

if ($lastpage === 0) {
   echo '<div align="center">You currently have no pics.<br />Post your first pic now!</div>';
   exit;
}
?>

<table width='954' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>

<?php
// $dropdown[img_id] = img_name
$dropdown = array();

// for performance sake, just run another query even though $sql already selects the data we want.
// this will be faster than for PHP to do.
$dropdown_sql = 'SELECT id, item_name FROM abcxyz WHERE user_id = ' . $member_id;
$dropdown_result = mysql_query($dropdown_sql) or trigger_error('Select SQL failed.', E_USER_ERROR);
$dropdown_menu = '<select name="pageno">';
while ($row = mysql_fetch_assoc($dropdown_result)) {
   $dropdown_menu .= '<option value="' . $row['id'] . '">' . $row['item_name'] . '</option>';
}

while ($row = mysql_fetch_assoc($result))
{
   $dropdown[$row['id']] = $row['item_name'];
   echo '<tr>';
   for ($e = 2; $e < 6; $e++)
   {
      echo '<td width="188" height="180"><div align="center"><img src="' . $row['imgpath'] . '" width="125" alt="image 1" /></div></td><td width="188"><div            align="center">';
      echo empty($row['imgpath' . $e])? 
         '<a href="picure2.php"><img src="images/uploadanother.png" border="0"></a>' : 
         '<img src="' . $row['imgpath' . $e] . '" width="125" alt="" /><a href="delete_image' . $e . '.php"><span style="color: red;"> X</span></a>';
      echo '</div></td>';
   }

   echo '</tr><tr><td height="43" colspan="4"><strong>Item Name:</strong><input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" />  &nbsp';
   echo $pageno == 1? ' Previous Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $prevpage . '"> Previous </a>(' . $pageno . ' of ' . $lastpage . ')';
   echo $pageno == $lastpage? ' Next Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $nextpage . '"> Next </a>';
   
   ?>
   
   </td>
   <td><div align="center"><input type="hidden" name="id" value="<?php echo $row['id']; ?>" size="25" /></div></td>
   </tr>
   <tr>
      <td height="116" colspan="4"><strong>Description:</strong> <textarea name="description" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
       <td><div align="center"><input type="submit" name="submit" id="submit" value="Update Item"></div></td>
   </tr>
   <tr>
      <td height="124" colspan="4"><strong>Seeking:</strong>       <textarea name="in_return" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
      <td><div align="center">';
   
   <?php
   if(isset($_SESSION['updatecomplete'])) {
      unset($_SESSION['updateerror']);
      echo $_SESSION['updatecomplete'];
   }
   if(isset($_SESSION['updateerror'])) {
      unset($_SESSION['updatecomplete']);
      echo $_SESSION['updateerror'];
   }
   if(isset($_SESSION['picupload'])) {
      unset($_SESSION['updatecomplete']);
      unset($_SESSION['updateerror']);
      echo $_SESSION['picupload'];
   }
   ?>
      </div><td>
   </tr>
   <tr>
      <td colspan="4"><input type="hidden" name="category" value="<?php echo $row['category']; ?>" size="25" /></td>
   </tr>
   </table>
}
</form>
<?php
$_SESSION['move_id'] = $row['id'];
$_SESSION['move_category'] = $row['category'];
$_SESSION['path_1'] = $row['imgpath'];
$_SESSION['path_2'] = $row['imgpath2'];
$_SESSION['path_3'] = $row['imgpath3'];
$_SESSION['path_4'] = $row['imgpath4'];
$_SESSION['path_5'] = $row['imgpath5'];
?>
      
      
      <form id="form3" name="form3" method="post" action="deletetrade.php">
        <div align="center">
          <?php
          $no_trades = $_SESSION['rid_of_delete_button'];
	  if($lastpage != 0)
          {
	    echo '<input type="submit" name="submit" id="submit" value="Delete Selected Item" />';
	  }
	  else
	  {
	    echo "";
	  }
	  ?>
          </div>
      <?php
if(isset($_SESSION['item_deleted_error']))
{
  unset($_SESSION['item_deleted']);
  unset($_SESSION['updateerror']);
  unset($_SESSION['updatecomplete']);
  unset($_SESSION['picupload']);
  echo $_SESSION['item_deleted_error'];
}
if(isset($_SESSION['item_deleted']))
{
  unset($_SESSION['item_deleted_error']);
  unset($_SESSION['item_deleted']);
  unset($_SESSION['updateerror']);
  unset($_SESSION['updatecomplete']);
  unset($_SESSION['picupload']);
  echo $_SESSION['item_deleted'];
}
?>
      </form>
      </div>
      <br />
      </td>
  </tr>
</table>
<p><br />
</p>
<p> </p>
<p>

</p>
<p> </p>
<p>  </p>
<p> </p>
</body>
</html>

Link to comment
Share on other sites

<?php
session_start();
include "connection.php";
echo '<form id="form2" name="form2" method="get" action="updatetrade.php">';

/*Lol loving the nested PHP tags but that wont work =( and you cant output anything to the screen before session_start(); */
$pageno = isset($_GET['pageno'])? intval($_GET['pageno']) : 1;

$findit = intval($_SESSION['id']);
$result = mysql_query('SELECT m.id, COUNT(*) AS count FROM abcxyz a INNER JOIN members m ON m.id = a.user_id WHERE m.username="' . $findit .'" LIMIT 1') or trigger_error('User not found.', E_USER_ERROR);
$member_info = mysql_fetch_row($result);

$member_id = intval($member_info[0]);
$numrows = intval($member_info[1]);
$rows_per_page = 1;

$_SESSION['rid_of_delete_button'] = $lastpage = ceil($numrows/$rows_per_page);
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];

$prevpage = $pageno-1;
$nextpage = $pageno+1;

if ($pageno > $lastpage) $pageno = $lastpage;
else if ($pageno < 1) $pageno = 1;

$limit = 'LIMIT '. ($pageno * $rows_per_page) . ',' . $rows_per_page;

$sql = <<<QUERY
SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return
FROM abcxyz
WHERE user_id = $member_id
$limit;
QUERY;

$result = mysql_query($sql) or trigger_error('Select SQL failed - ' . mysql_error(), E_USER_ERROR);

if ($lastpage === 0) {
   echo '<div align="center">You currently have no pics.<br />Post your first pic now!</div>';
   exit;
}
?>

<table width='954' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>

<?php
// $dropdown[img_id] = img_name
$dropdown = array();

// for performance sake, just run another query even though $sql already selects the data we want.
// this will be faster than for PHP to do.
$dropdown_sql = 'SELECT id, item_name FROM abcxyz WHERE user_id = ' . $member_id;
$dropdown_result = mysql_query($dropdown_sql) or trigger_error('Select SQL failed.', E_USER_ERROR);
$dropdown_menu = '<select name="pageno">';
while ($row = mysql_fetch_assoc($dropdown_result)) {
   $dropdown_menu .= '<option value="' . $row['id'] . '">' . $row['item_name'] . '</option>';
}

while ($row = mysql_fetch_assoc($sql)) {

   $dropdown[$row['id']] = $row['item_name'];

   echo '<tr>';
   for ($e = 2; $e < 6; $e++) {
      echo '<td width="188" height="180"><div align="center"><img src="' . $row['imgpath'] . '" width="125" alt="image 1" /></div></td><td width="188"><div align="center">';
      echo empty($row['imgpath' . $e])? 
         '<a href="picure2.php"><img src="images/uploadanother.png" border="0"></a>' : 
         '<img src="' . $row['imgpath' . $e] . '" width="125" alt="" /><a href="delete_image' . $e . '.php"><span style="color: red;"> X</span></a>';
      echo '</div></td>';
   }

   echo '</tr><tr><td height="43" colspan="4"><strong>Item Name:</strong><input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" />  &nbsp';
   echo $pageno == 1? ' Previous Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $prevpage . '"> Previous </a>(' . $pageno . ' of ' . $lastpage . ')';
   echo $pageno == $lastpage? ' Next Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $nextpage . '"> Next </a>';
   
   ?>
   
   </td>
   <td><div align="center"><input type="hidden" name="id" value="<?php echo $row['id']; ?>" size="25" /></div></td>
   </tr>
   <tr>
      <td height="116" colspan="4"><strong>Description:</strong> <textarea name="description" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
       <td><div align="center"><input type="submit" name="submit" id="submit" value="Update Item"></div></td>
   </tr>
   <tr>
      <td height="124" colspan="4"><strong>Seeking:</strong>       <textarea name="in_return" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
      <td><div align="center">';
   
   <?php
   if(isset($_SESSION['updatecomplete'])) {
      unset($_SESSION['updateerror']);
      echo $_SESSION['updatecomplete'];
   }
   if(isset($_SESSION['updateerror'])) {
      unset($_SESSION['updatecomplete']);
      echo $_SESSION['updateerror'];
   }
   if(isset($_SESSION['picupload'])) {
      unset($_SESSION['updatecomplete']);
      unset($_SESSION['updateerror']);
      echo $_SESSION['picupload'];
   }
   ?>
      </div><td>
   </tr>
   <tr>
      <td colspan="4"><input type="hidden" name="category" value="<?php echo $row['category']; ?>" size="25" /></td>
   </tr>
<?php
}
?>
   </table>
</form>

<?php
// doesn't matter if these are outside of the while loop
// the way they were defined, it would have the same effect.
$_SESSION['move_id'] = $row['id'];
$_SESSION['move_category'] = $row['category'];
$_SESSION['path_1'] = $row['imgpath'];
$_SESSION['path_2'] = $row['imgpath2'];
$_SESSION['path_3'] = $row['imgpath3'];
$_SESSION['path_4'] = $row['imgpath4'];
$_SESSION['path_5'] = $row['imgpath5'];

Link to comment
Share on other sites

A bit of debugging then.

<?php
session_start();
include "connection.php";
echo '<form id="form2" name="form2" method="get" action="updatetrade.php">';

/*Lol loving the nested PHP tags but that wont work =( and you cant output anything to the screen before session_start(); */
$pageno = isset($_GET['pageno'])? intval($_GET['pageno']) : 1;

$findit = intval($_SESSION['id']);
$result = mysql_query('SELECT m.id, COUNT(*) AS count FROM abcxyz a INNER JOIN members m ON m.id = a.user_id WHERE m.username="' . $findit .'" LIMIT 1') or trigger_error('User not found.', E_USER_ERROR);
$member_info = mysql_fetch_row($result);

$member_id = intval($member_info[0]);
$numrows = intval($member_info[1]);
var_dump($member_id, $numrows);
$rows_per_page = 1;

$_SESSION['rid_of_delete_button'] = $lastpage = ceil($numrows/$rows_per_page);
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];

$prevpage = $pageno-1;
$nextpage = $pageno+1;

if ($pageno > $lastpage) $pageno = $lastpage;
else if ($pageno < 1) $pageno = 1;

$limit = 'LIMIT '. ($pageno * $rows_per_page) . ',' . $rows_per_page;

$sql = <<<QUERY
SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return
FROM abcxyz
WHERE user_id = $member_id
$limit;
QUERY;

$result = mysql_query($sql) or trigger_error('Select SQL failed - ' . mysql_error(), E_USER_ERROR);

if ($lastpage === 0) {
   echo '<div align="center">You currently have no pics.<br />Post your first pic now!</div>';
   exit;
}
?>

<table width='954' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>

<?php
// $dropdown[img_id] = img_name
$dropdown = array();

// for performance sake, just run another query even though $sql already selects the data we want.
// this will be faster than for PHP to do.
$dropdown_sql = 'SELECT id, item_name FROM abcxyz WHERE user_id = ' . $member_id;
$dropdown_result = mysql_query($dropdown_sql) or trigger_error('Select SQL failed.', E_USER_ERROR);
$dropdown_menu = '<select name="pageno">';
while ($row = mysql_fetch_assoc($dropdown_result)) {
   $dropdown_menu .= '<option value="' . $row['id'] . '">' . $row['item_name'] . '</option>';
}

while ($row = mysql_fetch_assoc($sql)) {

   $dropdown[$row['id']] = $row['item_name'];

   echo '<tr>';
   for ($e = 2; $e < 6; $e++) {
      echo '<td width="188" height="180"><div align="center"><img src="' . $row['imgpath'] . '" width="125" alt="image 1" /></div></td><td width="188"><div align="center">';
      echo empty($row['imgpath' . $e])? 
         '<a href="picure2.php"><img src="images/uploadanother.png" border="0"></a>' : 
         '<img src="' . $row['imgpath' . $e] . '" width="125" alt="" /><a href="delete_image' . $e . '.php"><span style="color: red;"> X</span></a>';
      echo '</div></td>';
   }

   echo '</tr><tr><td height="43" colspan="4"><strong>Item Name:</strong><input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" />  &nbsp';
   echo $pageno == 1? ' Previous Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $prevpage . '"> Previous </a>(' . $pageno . ' of ' . $lastpage . ')';
   echo $pageno == $lastpage? ' Next Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $nextpage . '"> Next </a>';
   
   ?>
   
   </td>
   <td><div align="center"><input type="hidden" name="id" value="<?php echo $row['id']; ?>" size="25" /></div></td>
   </tr>
   <tr>
      <td height="116" colspan="4"><strong>Description:</strong> <textarea name="description" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
       <td><div align="center"><input type="submit" name="submit" id="submit" value="Update Item"></div></td>
   </tr>
   <tr>
      <td height="124" colspan="4"><strong>Seeking:</strong>       <textarea name="in_return" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
      <td><div align="center">';
   
   <?php
   if(isset($_SESSION['updatecomplete'])) {
      unset($_SESSION['updateerror']);
      echo $_SESSION['updatecomplete'];
   }
   if(isset($_SESSION['updateerror'])) {
      unset($_SESSION['updatecomplete']);
      echo $_SESSION['updateerror'];
   }
   if(isset($_SESSION['picupload'])) {
      unset($_SESSION['updatecomplete']);
      unset($_SESSION['updateerror']);
      echo $_SESSION['picupload'];
   }
   ?>
      </div><td>
   </tr>
   <tr>
      <td colspan="4"><input type="hidden" name="category" value="<?php echo $row['category']; ?>" size="25" /></td>
   </tr>
<?php
}
?>
   </table>
</form>

<?php
// doesn't matter if these are outside of the while loop
// the way they were defined, it would have the same effect.
$_SESSION['move_id'] = $row['id'];
$_SESSION['move_category'] = $row['category'];
$_SESSION['path_1'] = $row['imgpath'];
$_SESSION['path_2'] = $row['imgpath2'];
$_SESSION['path_3'] = $row['imgpath3'];
$_SESSION['path_4'] = $row['imgpath4'];
$_SESSION['path_5'] = $row['imgpath5'];

Link to comment
Share on other sites

Sorry for the delay. I was busy with something else.

 

Okay so for some reason, the SQL isn't picking up any user data.

<?php
session_start();
include "connection.php";
echo '<form id="form2" name="form2" method="get" action="updatetrade.php">';

/*Lol loving the nested PHP tags but that wont work =( and you cant output anything to the screen before session_start(); */
$pageno = isset($_GET['pageno'])? intval($_GET['pageno']) : 1;

$findit = intval($_SESSION['id']);
$sql = 'SELECT m.id, COUNT(*) AS count FROM abcxyz a RIGHT OUTER JOIN members m ON m.id = a.user_id WHERE m.username="' . $findit .'" LIMIT 1';
var_dump($sql);
$result = mysql_query($sql) or trigger_error('User not found.', E_USER_ERROR);
$member_info = mysql_fetch_row($result);

$member_id = intval($member_info[0]);
$numrows = intval($member_info[1]);
$rows_per_page = 1;

$_SESSION['rid_of_delete_button'] = $lastpage = ceil($numrows/$rows_per_page);
$_SESSION['last_page'] = $_SERVER['PHP_SELF'];

$prevpage = $pageno-1;
$nextpage = $pageno+1;

if ($pageno > $lastpage) $pageno = $lastpage;
else if ($pageno < 1) $pageno = 1;

$limit = 'LIMIT '. ($pageno * $rows_per_page) . ',' . $rows_per_page;

$sql = <<<QUERY
SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return
FROM abcxyz
WHERE user_id = $member_id
$limit;
QUERY;

$result = mysql_query($sql) or trigger_error('Select SQL failed - ' . mysql_error(), E_USER_ERROR);

if ($lastpage === 0) {
   echo '<div align="center">You currently have no pics.<br />Post your first pic now!</div>';
   exit;
}
?>

<table width='954' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>

<?php
// $dropdown[img_id] = img_name
$dropdown = array();

// for performance sake, just run another query even though $sql already selects the data we want.
// this will be faster than for PHP to do.
$dropdown_sql = 'SELECT id, item_name FROM abcxyz WHERE user_id = ' . $member_id;
$dropdown_result = mysql_query($dropdown_sql) or trigger_error('Select SQL failed.', E_USER_ERROR);
$dropdown_menu = '<select name="pageno">';
while ($row = mysql_fetch_assoc($dropdown_result)) {
   $dropdown_menu .= '<option value="' . $row['id'] . '">' . $row['item_name'] . '</option>';
}

while ($row = mysql_fetch_assoc($sql)) {

   $dropdown[$row['id']] = $row['item_name'];

   echo '<tr>';
   for ($e = 2; $e < 6; $e++) {
      echo '<td width="188" height="180"><div align="center"><img src="' . $row['imgpath'] . '" width="125" alt="image 1" /></div></td><td width="188"><div align="center">';
      echo empty($row['imgpath' . $e])? 
         '<a href="picure2.php"><img src="images/uploadanother.png" border="0"></a>' : 
         '<img src="' . $row['imgpath' . $e] . '" width="125" alt="" /><a href="delete_image' . $e . '.php"><span style="color: red;"> X</span></a>';
      echo '</div></td>';
   }

   echo '</tr><tr><td height="43" colspan="4"><strong>Item Name:</strong><input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" />  &nbsp';
   echo $pageno == 1? ' Previous Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $prevpage . '"> Previous </a>(' . $pageno . ' of ' . $lastpage . ')';
   echo $pageno == $lastpage? ' Next Item ' : '<a href="' . $_SERVER['PHP_SELF'] . '"?pageno=' . $nextpage . '"> Next </a>';
   
   ?>
   
   </td>
   <td><div align="center"><input type="hidden" name="id" value="<?php echo $row['id']; ?>" size="25" /></div></td>
   </tr>
   <tr>
      <td height="116" colspan="4"><strong>Description:</strong> <textarea name="description" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
       <td><div align="center"><input type="submit" name="submit" id="submit" value="Update Item"></div></td>
   </tr>
   <tr>
      <td height="124" colspan="4"><strong>Seeking:</strong>       <textarea name="in_return" cols="75" rows="5"><?php echo $row['description']; ?></textarea></td>
      <td><div align="center">';
   
   <?php
   if(isset($_SESSION['updatecomplete'])) {
      unset($_SESSION['updateerror']);
      echo $_SESSION['updatecomplete'];
   }
   if(isset($_SESSION['updateerror'])) {
      unset($_SESSION['updatecomplete']);
      echo $_SESSION['updateerror'];
   }
   if(isset($_SESSION['picupload'])) {
      unset($_SESSION['updatecomplete']);
      unset($_SESSION['updateerror']);
      echo $_SESSION['picupload'];
   }
   ?>
      </div><td>
   </tr>
   <tr>
      <td colspan="4"><input type="hidden" name="category" value="<?php echo $row['category']; ?>" size="25" /></td>
   </tr>
<?php
}
?>
   </table>
</form>

<?php
// doesn't matter if these are outside of the while loop
// the way they were defined, it would have the same effect.
$_SESSION['move_id'] = $row['id'];
$_SESSION['move_category'] = $row['category'];
$_SESSION['path_1'] = $row['imgpath'];
$_SESSION['path_2'] = $row['imgpath2'];
$_SESSION['path_3'] = $row['imgpath3'];
$_SESSION['path_4'] = $row['imgpath4'];
$_SESSION['path_5'] = $row['imgpath5'];

Link to comment
Share on other sites

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.