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
Share on other sites

Here's the error:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Phone_Feed' WHERE 'Model.Name'='Nokia'' at line 1

Link to comment
Share on other sites

Your field name isn't Model.name is it? That will cause all sorts of dramas as a period seperated identifier tells mysql to look in the table Model for a field called Name.

 

Id'e suggest renaming your field to Model_Name.

Link to comment
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?

Link to comment
Share on other sites

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;
}
?> 

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.