Jump to content

[SOLVED] Something wrong in this query..has to be simple I just cant get it?


jaxdevil

Recommended Posts

It is not returning any results, when I run that exact $sql in phpmyadmin it returns results. Anyone see what I am missing?

 

<?
require($_SERVER['DOCUMENT_ROOT'].'/includes/configs/sql_connect.php');
$sql = 'SELECT * FROM products_description WHERE model_number=\'JT20-A8450\'';
$query = mysql_query($sql) or die ("MySQL Error: " . mysql_error());
while($row = mysql_fetch_array($query)){
$descriptions = $row['$id'];
echo $descriptions;
echo $row[$description];
}
?>

Link to comment
Share on other sites

Try this:

 

<?
require($_SERVER['DOCUMENT_ROOT'].'/includes/configs/sql_connect.php');
$sql = "SELECT * FROM products_description WHERE model_number=\'JT20-A8450\'";
$query = mysql_query($sql) or die ("MySQL Error: " . mysql_error());
while($row = mysql_fetch_array($query)){
$descriptions = $row['$id'];
echo $descriptions;
echo $row[$description];
}
?>

Link to comment
Share on other sites

 WHERE model_number=\'JT20-A8450\'"

 

why do you have the slashes? I think that may be the issue try removing those slashes, as they arent needed cause your not trying to break any quotes with them.. so above to..

 

 WHERE model_number='JT20-A8450'"

 

does that help?

Link to comment
Share on other sites

better yet..

replace..

 

$sql = mysql_query("SELECT * FROM products_description WHERE model_number='JT20-A8450'");
$query = mysql_num_rows($sql); // returns number of rows should you need that
$query_a = mysql_fetch_array($sql); // returns the array of info from the row

while($row = mysql_fetch_array($query)){
$descriptions = $row['$id'];
echo $descriptions;
echo $row[$description];
}

Link to comment
Share on other sites

Nope, I put the document root so I can move the script between websites. I tried without the slashes and with the actual connection string on the page, i put sample text below the script of 'test' to make sure the script wasn't breaking. So the only thing output to the browser is the text 'test'. Here is the code, with the slashes removed, and the connection string with the username password changed of course. It is the right connection string and the fields are in the database. I even tried like below with a LIKE statement and just a wildcard, still nothing.

 

<?
mysql_connect('localhost','xxx_xxx','xxx');
mysql_select_db('xxx_xxx');
$sql = "SELECT * FROM products_description WHERE model_number LIKE '%'";
$query = mysql_query($sql) or die ("MySQL Error: " . mysql_error());
while($row = mysql_fetch_array($query)){
$descriptions = $row['$id'];
echo $descriptions;
echo $row[$description];
}
?>

Link to comment
Share on other sites

I tried with the below, nothing returned other than the text 'test':

 

$sql = "SELECT * FROM products_description WHERE model_number LIKE '%'";
$query = mysql_num_rows($sql); // returns number of rows should you need that
$query_a = mysql_fetch_array($sql); // returns the array of info from the row

while($row = mysql_fetch_array($query_a)){
$descriptions = $row['$id'];
echo $descriptions;
echo $row[$description];
}

Link to comment
Share on other sites

No, I added 'test' as text after the code so I could make sure the script wasn't breaking.

 

I figured it out though:

 

<?
require($_SERVER['DOCUMENT_ROOT'].'/includes/configs/sql_connect.php');
$result = mysql_query("SELECT * FROM products_description WHERE model_number='JT20-A8450'") or die(mysql_error());

$row = mysql_fetch_array($result); 

echo $row['id'];
echo "<br>";
echo $row['description'];
?>

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.