MySQL help!!!!!

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   MySQL help!!!!!
wolf
CZ Active Member
usa.gif indiana.gif
Occupation: Student; Flash, HTML, PHP developer
Age: 34
Gender: Male
Status: Offline
Joined: Jul 25, 2003
0.02 posts per day
Posts: 168
Points: 10,417
AIM Address Yahoo Messenger MSN Messenger 
Ok sorry for more topics...lol...

Here's my problem. I'm clicking on a link and what it is supposed to do is connect to the DB, search for a specific table, specific field, and then echo what all is in that feild. here is the code im using:
<?php

@ $database = mysql_pconnect("localhost", "UsernamE", "PassworD");

if (!$database)
{
   echo "Error: Could not connect to database.";
   exit;
}

mysql_select_db("DatabasE");

$query = "SELECT Email FROM nuke_themes";
$result = mysql_query($query);

$query2 = "SELECT Homepage FROM nuke_themes";
$result2 = mysql_query($query2);

$query3 = "SELECT Themename FROM nuke_themes";
$result3 = mysql_query($query3);


if (!$result || !$result2 || !$result3)
{
    echo "There are no requests for a new theme.";
    exit;
}


$row = mysql_fetch_array($result);
$new = stripslashes($row["Email"]);

$row = mysql_fetch_array($result2);
$new2 = stripslashes($row["Homepage"]);

$row = mysql_fetch_array($result3);
$new3 = stripslashes($row["Themename"]);



echo "$new<br>";
echo "$new2<br>";
echo "$new3<br>";


?>

It's displaying only one object from the feilds... I have currently 4 things in each column. 4 email addresses, 4 homepages, and 4 themenames...all tests. Only one from each group is showing up in the echo...

Anyone know why??

Srry for the multiple topics...

Wolf.



_________________
[ Register or login to view links on this board.]
Back to top Reply with quote
#2   re: MySQL help!!!!!
Kelly_Hero
PayPal Donation
CZ Revered Member
 Codezwiz Site Donator
usa.gif southcarolina.gif
Occupation: Web Developer
Age: 59
Gender: Female
Website:
Status: Offline
Joined: Aug 20, 2003
0.49 posts per day
Posts: 3765
Points: 351,412
   
It's because you're not telling it to display more than one row. You need a loop in there so that when it gets finished displaying everything in the first row, it moves to the next row and displays everything in that row and so on until it has displayed all the rows.



Back to top Reply with quote
#3   re: MySQL help!!!!!
wolf
CZ Active Member
usa.gif indiana.gif
Occupation: Student; Flash, HTML, PHP developer
Age: 34
Gender: Male
Status: Offline
Joined: Jul 25, 2003
0.02 posts per day
Posts: 168
Points: 10,417
AIM Address Yahoo Messenger MSN Messenger 
ok, can you help me with this loop? Here is what I have now:

<?php

@ $database = mysql_pconnect("localhost", "UseR", "PassworD");

if (!$database)
{
   echo "Error: Could not connect to database.";
   exit;
}

mysql_select_db("DatabasE");

$query = "SELECT Email FROM nuke_themes";
$result = mysql_query($query);

$query2 = "SELECT Homepage FROM nuke_themes";
$result2 = mysql_query($query2);

$query3 = "SELECT Themename FROM nuke_themes";
$result3 = mysql_query($query3);


if (!$result || !$result2 || !$result3)
{
    echo "There are no requests for a new theme.";
    exit;
}




for($i=0; $i<mysql_affected_rows(); $i++)
{
    $row = mysql_fetch_array($result);
}
$new = stripslashes($row["Email"]); 



for($i2=0; $i2<mysql_affected_rows(); $i2++)
{
    $row = mysql_fetch_array($result2);
}
$new2 = stripslashes($row["Homepage"]);



for($i3=0; $i3<mysql_affected_rows(); $i3++)
{
     $row = mysql_fetch_array($result3);
}
$new3 = stripslashes($row["Themename"]);

echo "<table border=\"2\">";
echo "<tr>";
echo "<td><center><b>Email:</b></center></td>";
echo "<td><center><b>Home&nbspPage:</b></center></td>";
echo "<td><center><b>Theme&nbspName:</b></center></td>";
echo "</tr>";
echo "<tr>";
echo "<td><center>$new</center></td>";
echo "<td><center>$new2</center></td>";
echo "<td><center>$new3</center></td>";
echo "</tr>";
echo "</table>";


?>


That is still displaying only one object from my rows...is there another method i should be using?

Thanks.



_________________
[ Register or login to view links on this board.]
Back to top Reply with quote
#4   re: MySQL help!!!!!
Kelly_Hero
PayPal Donation
CZ Revered Member
 Codezwiz Site Donator
usa.gif southcarolina.gif
Occupation: Web Developer
Age: 59
Gender: Female
Website:
Status: Offline
Joined: Aug 20, 2003
0.49 posts per day
Posts: 3765
Points: 351,412
   
Try this:
<?php @ $database = mysql_pconnect("localhost", "UseR", "PassworD");

if (!$database)
{
   echo "Error: Could not connect to database.";
   exit;
}
mysql_select_db("DatabasE");
$query = "SELECT Email, Homepage, Themename FROM nuke_themes";
$result = mysql_query($query);
$rows = mysql_fetch_assoc($result);
$total_rows = mysql_num_rows($result);

if (!isset($result) || ($result == ""))
{
    echo "There are no requests for a new theme.";
}
else {
      $req = "";
      $i = 0;
      if ($total_rows> 0) {
      mysql_data_seek ( $result, 0 );
      while ($row =  mysql_fetch_assoc($result)) {
      $email = $row['Email'];
      $homepage = $row['homepage'];
      $themename = $row['Themename'];

      echo "<table border=\"2\"><tr>";
      echo "<td align=\"center\"><b>Email:</b></td>";
      echo "<td align=\"center\"><b>Home Page:</b></td>";
      echo "<td align=\"center\"><center><b>Theme Name:</b></td></tr><tr>";
      echo "<td align=\"center\">$email</td>";
      echo "<td align=\"center\">$homepage</td>";
      echo "<td align=\"center\">$themename</td></tr></table>";
         } //end loop
      }
      $i++;
      echo "$req";
}
?>



Back to top Reply with quote
#5   re: MySQL help!!!!!
wolf
CZ Active Member
usa.gif indiana.gif
Occupation: Student; Flash, HTML, PHP developer
Age: 34
Gender: Male
Status: Offline
Joined: Jul 25, 2003
0.02 posts per day
Posts: 168
Points: 10,417
AIM Address Yahoo Messenger MSN Messenger 
ok, im on a school computer at the moment, but i will try it when i get home...thanks kelly!




_________________
[ Register or login to view links on this board.]
Back to top Reply with quote
#6   re: MySQL help!!!!!
wolf
CZ Active Member
usa.gif indiana.gif
Occupation: Student; Flash, HTML, PHP developer
Age: 34
Gender: Male
Status: Offline
Joined: Jul 25, 2003
0.02 posts per day
Posts: 168
Points: 10,417
AIM Address Yahoo Messenger MSN Messenger 
Worked really nicely, thanks Kelly.

I have one more question. This is taking in requests, so there will be a page posting all the requests form the database. If that request was made, i will want to delete that request from the database. I have looked at ALTER...and that is just changing the fields, and ive looked at dropping a row...then in the page posting all the requests, in that PHP code...I could make an if statement, and check whether or not the table exists. If it doesnt, make it. If it does, skip "Creat Table" and go on to adding the information into it.

Is there a better way to do that? I think im going to go with the second way...but if theres a shorter better way, im all ears.

Thanks, Wolf.




_________________
[ Register or login to view links on this board.]
Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum