Jump to content

Wierd PHP & MySQL Happening


lpxxfaintxx

Recommended Posts

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:

[code]
$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>';[/code]


Help would be GREATLY appreciated.
Link to comment
Share on other sites

$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>';
Link to comment
Share on other sites

Thanks everyone.

One more question:

[code]
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>";[/code]



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]
Link to comment
Share on other sites

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:

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

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

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

Hope that helps!
Link to comment
Share on other sites

Err, I used the code many many times, and they worked perfectly. The only new part this time is [code]<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>[/code]


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

[code]<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>[/code]

to

[code]
$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>[/code]
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.