Jump to content


Photo

Wierd PHP & MySQL Happening


  • Please log in to reply
5 replies to this topic

#1 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 16 June 2006 - 04:57 PM

Hello,

I am making a tutorial CMS, but I'm facing a very wierd problem. I have an admin section where I can approve or deny a tutorial. But, when I add a tutorial, the most recent tutorial added is not there. For example, lets say I added tutorial 1. In the admin section, tutorial 1 is not there. Then Bob comes, and adds tutorial 2. Now tutorial 1 is showing, but 2 is not.

This is what I have so far:

$sql = "SELECT * FROM `tutorials` WHERE `activation` =0";
$result=mysql_query($sql);

// Define $color=1
$color="1";
$rows=mysql_fetch_array($result);
echo '<table width="500" border="1" align="center" cellpadding="2" cellspacing="0">';
echo "<tr bgcolor='#666666'>
<td><font color = white>Name</font></td><td><font color = white>Category</font></td><td><font color = white>URL</font></td><td><font color = white>Description</font></td>
</tr>";
while($rows=mysql_fetch_array($result)){

$cat = $rows['catid'];
$sql2 = "SELECT * FROM `category` WHERE `cat_id` = '$cat'";

$result2=mysql_query($sql2);
$rows2=mysql_fetch_array($result2);

if($color==1){
echo "<tr bgcolor='#eeeeee' onmouseover='style.backgroundColor=\"#3D59AB\";' onmouseout=\"style.backgroundColor='#eeeeee'\">
<td>".$rows['name']."</td><td>".$rows2['category']."</td><td><a href=".$rows['url'].">Link</a></td><td>".$rows['description']."</td>
</tr>";
// Set $color==2, for switching to other color
$color="2";
}

// When $color not equal 1, use this table row color
else {
echo "<tr bgcolor='#c0c0c0' onmouseover='style.backgroundColor=\"#3D59AB\";' onmouseout=\"style.backgroundColor='#c0c0c0'\">
<td>".$rows['name']."</td><td>".$rows2['category']."</td><td><a href=".$rows['url'].">Link</a></td><td>".$rows['description']."</td>
</tr>";
// Set $color back to 1
$color="1";
}
}
echo '</table>';


Help would be GREATLY appreciated.

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 16 June 2006 - 05:03 PM

you aren't looping your mysql_fetch_array result. each call to it fetches 1 row. so you need to loop it for each row.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 jvrothjr

jvrothjr
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts
  • LocationOhio

Posted 16 June 2006 - 05:06 PM

$sql = "SELECT * FROM `tutorials` WHERE `activation` = 0";
$result=mysql_query($sql);

// Define $color=1
$color="1";


//////////////////////////////////////////////
///Remove this line it gets the first line ///
/// then your While($row) pulls the second ///
//////////////////////////////////////////////
/// $rows=mysql_fetch_array($result); ///
//////////////////////////////////////////////


echo "<table width="500" border=1 align=center cellpadding=2 cellspacing=0>";
echo "<tr bgcolor='#666666'>
<td><font color = white>Name</font></td><td><font color = white>Category</font></td><td><font color = white>URL</font></td><td><font color = white>Description</font></td>
</tr>";
while($rows=mysql_fetch_array($result)){

$cat = $rows['catid'];
$sql2 = "SELECT * FROM `category` WHERE `cat_id` = '$cat'";

$result2=mysql_query($sql2);
$rows2=mysql_fetch_array($result2);

if($color==1){
echo "<tr bgcolor='#eeeeee' onmouseover='style.backgroundColor=\"#3D59AB\";' onmouseout=\"style.backgroundColor='#eeeeee'\">
<td>".$rows['name']."</td><td>".$rows2['category']."</td><td><a href=".$rows['url'].">Link</a></td><td>".$rows['description']."</td>
</tr>";
// Set $color==2, for switching to other color
$color="2";
}
// When $color not equal 1, use this table row color
else {
echo "<tr bgcolor='#c0c0c0' onmouseover='style.backgroundColor=\"#3D59AB\";' onmouseout=\"style.backgroundColor='#c0c0c0'\">
<td>".$rows['name']."</td><td>".$rows2['category']."</td><td><a href=".$rows['url'].">Link</a></td><td>".$rows['description']."</td>
</tr>";
// Set $color back to 1
$color="1";
}
}
echo '</table>';
If you understand everything you know nothing!

http://rcchjr.awardspace.com/

#4 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 16 June 2006 - 05:20 PM

Thanks everyone.

One more question:

if($color==1){
echo "<tr bgcolor='#eeeeee' onmouseover='style.backgroundColor=\"#3D59AB\";' onmouseout=\"style.backgroundColor='#eeeeee'\">
<td>".$rows['name']."</td><td>".$rows2['category']."</td><td><a href=".$rows['url'].">Link</a></td><td>".$rows['description']."</td><td><a href="approval.php?id=".$rows['url']."&act=1">Yes</a><br><font color=red><a href="approval.php?id=".$rows['id']."&act=0">No</a></font></td></tr>";
LINE 134.. wierd eh?-->  // Set $color==2, for switching to other color
$color="2";
}

// When $color not equal 1, use this table row color
else {
echo "<tr bgcolor='#c0c0c0' onmouseover='style.backgroundColor=\"#3D59AB\";' onmouseout=\"style.backgroundColor='#c0c0c0'\">
<td>".$rows['name']."</td><td>".$rows2['category']."</td><td><a href=".$rows['url'].">Link</a></td><td>".$rows['description']."</td><td><a href="approval.php?id=".$rows['url']."&act=1">Yes</a><br><font color=red><a href="approval.php?id=".$rows['id']."&act=0">No</a></font></td>
</tr>";



I am getting [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/informed/public_html/projects/tuts/approval.php on line 134[/quote]

#5 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 16 June 2006 - 06:02 PM

I didn't check all of it, but I can see in my editor that something is off with the line you are echo'ing. You have a ";" in the middle of your <tr> definition and some odd flips back and forth when using single quotes and double quotes. See the examle, but you go from defining the onmouseover with single quotes to the onmouseout with doublequotes.

I would break these down and make sure they all work in smaller pieces then move them back to one.

For example:

echo "<tr bgcolor='#eeeeee' onmouseover='style.backgroundColor=\"#3D59AB\";' onmouseout=\"style.backgroundColor='#eeeeee'\">

I think should be this:
echo "<tr onmouseover='style.backgroundColor=\"#3D59AB\" 'onmouseout='style.backgroundColor="#eeeeee"\'>

That's obviously not the full echo from your script, just the part I saw some problems with.

Hope that helps!

#6 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 16 June 2006 - 06:13 PM

Err, I used the code many many times, and they worked perfectly. The only new part this time is
<a href="approval.php?id=".$rows['url']."&act=1">Yes</a><br><font color=red><a href="approval.php?id=".$rows['id']."&act=0">No</a></font>


I also tried removing that part, and it worked... so it has to be it.

-----------------------------------------------------------

EDIT: Problem found...

All I had to do was change

<a href="approval.php?id=".$rows['url']."&act=1">Yes</a><br><font color=red><a href="approval.php?id=".$rows['id']."&act=0">No</a></font>

to

$link1 = 'approval.php?id='.$id.'&act=1';
$link2 = 'approval.php?id='.$id.'&act=0';

<a href=".$link1.">Yes</a><br><font color=red><a href=".$link2.">No</a></font>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users