Simon Staton
Simon Staton

Reputation: 4505

Displaying Value Field from Database in PHP

I am fairly new to PHP and MySQL and am trying to write a code where I display all the values of the column value where the column attribute_id = 64. This is what I have written but I can't seem to get it to display:

<? 
mysql_connect ("localhost","cpsdev_mage1","**********"); 
mysql_select_db ("cpsdev_mage1"); 

$sql = "select 'value' from mage_catalogsearch_fulltext 
WHERE 'Attribute_id' = 64"; 
$result = mysql_query ($sql) or die($myQuery."<br/><br/>".mysql_error()); 

while($row = mysql_fetch_array($result))
{
  echo $row['value'];
}

?>

Upvotes: 0

Views: 285

Answers (5)

Rubin Porwal
Rubin Porwal

Reputation: 3845

As a solution to your problem please try executing the below query

          $sql = "select value from mage_catalogsearch_fulltext 
          WHERE 'Attribute_id' = 64"; 

In sql query columns do not need to be enclosed in quotes. and also prefer using php full tags instead of short tags as in some servers short tags might be set to off which can create problems across different server environments

Upvotes: 0

swapnesh
swapnesh

Reputation: 26732

Try this code-

<?php
mysql_connect ("localhost","cpsdev_mage1","**********"); 
mysql_select_db ("cpsdev_mage1"); 

$sql = "select value from mage_catalogsearch_fulltext WHERE Attribute_id = 64"; 
$result = mysql_query ($sql) or die($myQuery."<br/><br/>".mysql_error()); 

while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
  echo $row['value'];
}

?>

What i added --

  1. Changed <? to <?php.
  2. Changed 'value' to value & 'Attribute_id' to Attribute_id in query.
  3. Added mysql_fetch_array($result,MYSQL_ASSOC).

Upvotes: 0

user1518659
user1518659

Reputation: 2246

$sql = "select value from mage_catalogsearch_fulltext WHERE Attribute_id = 64"; 

Also your code should begin with <?php not <?

Upvotes: 0

Chris
Chris

Reputation: 5605

<?php // instead of <?

  mysql_connect ("localhost","cpsdev_mage1","**********"); 
  mysql_select_db ("cpsdev_mage1"); 

  $sql = "SELECT value FROM mage_catalogsearch_fulltext 
  WHERE Attribute_id = 64"; // <------------ removed un-needed single quotes
  $result = mysql_query ($sql) or die("<br/><br/>".mysql_error()); // removed '$myQuery'

  while($row = mysql_fetch_array($result))
  {
    echo $row['value'];
  }

?>

Upvotes: 0

bounty_killer525
bounty_killer525

Reputation: 89

Try this :-

  $sql = "select value from mage_catalogsearch_fulltext WHERE Attribute_id = 64"; 

Upvotes: 1

Related Questions