Jump to content

Warning: mysql_fetch_assoc():


Jamz

Recommended Posts

Hi There,

 

Im currently having problems when i add a WHERE statment into my SQL... this is the code i have so far:

 

<?php 
$brand = $_GET['brand'];
$count = 0;
$stop;
include('images/config.php');
$database = mysql_connect($hostname,$username,$password) or die("Could not connect to server");
mysql_select_db($table,$database) or die("Could not find table");
$query = "SELECT * FROM 'Phone_Feed' WHERE 'Model.Name'='$brand'";
$result = mysql_query ($query);
while ($row = mysql_fetch_assoc($result)) {
$name = $row['Model.Name'];
$img = $row['Model.ImageSmall'];  

while ($count < 6){
echo '<td width="100" align="center" bgcolor="#CCCCCC" class="deals"><strong>'.$name.'</strong></td>';
$stop = $name;
$count++;
}
$count=0;
$stop=0;
echo '</tr><tr>';
while ($count < 6){
echo '<td align="center" valign="middle" class="deals"><img src="'.$img.'" alt="" /></td>';
$count++;
}
echo '</tr><tr><td colspan="8" align="center" valign="middle"></td></tr>';
$count=0;
}
?> 

 

Now if i remove the WHERE the code works, but i need the WHERE to sort out all the phones.

 

Im not sure what is wrong with it, and i cannot see anything

 

Cheers

 

James

Link to comment
https://forums.phpfreaks.com/topic/96606-warning-mysql_fetch_assoc/
Share on other sites

Aye i just realised that... the problem is, the whole database is like that...

 

What it is you see, the database is imported from an comma file into mysql, and more or less every field has a . inbetween... Is there no work around without having to change the .'s?

Code now looks like the following:

 

 <?php 
$brand = $_GET['brand'];
$count = 0;
$stop;
include('images/config.php');
$database = mysql_connect($hostname,$username,$password) or die("Could not connect to server");
mysql_select_db($table,$database) or die("Could not find table");
$query = "SELECT * FROM Phone_Feed WHERE `Model.Name`='$brand'";
$result = mysql_query ($query) or die(mysql_error());;
while ($row = mysql_fetch_assoc($result)) {
$name = $row['Model.Name'];
$img = $row['Model.ImageSmall'];  

while ($count < 6){
echo '<td width="100" align="center" bgcolor="#CCCCCC" class="deals"><strong>'.$name.'</strong></td>';
$stop = $name;
$count++;
}
$count=0;
$stop=0;
echo '</tr><tr>';
while ($count < 6){
echo '<td align="center" valign="middle" class="deals"><img src="'.$img.'" alt="" /></td>';
$count++;
}
echo '</tr><tr><td colspan="8" align="center" valign="middle"></td></tr>';
$count=0;
}
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.