Be a Supporter!

mySQL... how do I do this?

  • 134 Views
  • 1 Reply
New Topic Respond to this Topic
omega3D
omega3D
  • Member since: Mar. 27, 2004
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
mySQL... how do I do this? 2005-06-23 23:25:15 Reply

I run this code:
mysql_connect("localhost", "BLAH", "OMFG CENSOR");
mysql_select_db("OMFGWTF");
$table = mysql_query("SELECT * FROM `forum`");
$topics = mysql_fetch_assoc($table);

Here's my goal: To individually read every value in the table and process it accordingly.
For example, here's the actual content of the database:
array (
var1 => 0
var2 => "OMG"
var3 => 6
)
array (
var1 => 1
var2 => "WTF"
var3 => 6
)
So I want to go down this list and process each entry in this table seperatly; something like this:
foreach($topics as $check) {
if($check == "OMG") {
echo "There is an entry that contains \"OMG\".<br />";
} else {
echo "This entry is not \"OMG\".<br />";
}
}

I tried that code, but it only outputs the first row in the table. But do you get what I mean? How do I do this?

AlternateAccount
AlternateAccount
  • Member since: Jun. 21, 2003
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to mySQL... how do I do this? 2005-06-23 23:39:46 Reply

You should try something like
mysql_connect("localhost", "BLAH", "OMFG CENSOR");
mysql_select_db("OMFGWTF");
$table = mysql_query("SELECT * FROM `forum`");
while($array = mysql_fetch_array($table)) {
$var1 = $array['var1'];
$var2 = $array['var2'];
$var3 = $array['var3'];
if($var2 == 'omg') {
echo 'omg';
} else {
echo 'not omfg.';
}
}