PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
slomotion
Forum Newbie
Posts: 13 Joined: Fri Jun 22, 2007 9:15 pm
Post
by slomotion » Wed Jun 27, 2007 12:59 am
Beginner here (again) trying to find out how to do a list of the column names. I am trying to use the mysql_field_name to do so, with an if statement. The problem is that there is no entries that are recognized or displayed. I dont know what could possibly be wrong because there should be some returns.
Here is the text
Code: Select all
<?php
error_reporting(0);
function mysqls_mad()
{
echo "MySQL said: Error: " . mysql_errno() . ' - ' . mysql_error();
exit();
}
if (!is_resource(($dbcon = mysql_connect("db949.perfora.net", "dbo207711380", "##PASS##"))))
{
mysqls_mad();
}
if (!mysql_select_db('db207711380', $dbcon))
{
mysqls_mad();
}
$input = $_GET["flavor"];
if (false === ($result = mysql_query("SELECT * FROM `flavors` WHERE 'flavor'='$input'")))
{
mysqls_mad();
}
echo "<h1>$flavor</h1>";
$number_of_rows = mysql_num_rows($result);
echo "<b>$number_of_rows Flavors</b>";
$y=mysql_num_fields($result);
for ($x=0; $x<$y; $x++) {
echo mysql_field_name($result,$y)."<br>";
}
?>
I use an input $_GET to get what the flavor should do.
Eventually I want to only display the ones that arnt null but for now Im just trying to do.
Thanks
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Wed Jun 27, 2007 1:04 am
I'm just going to type something out for you real quick. Please download the PHP manual and practice looking up functions..
Change this
Code: Select all
echo "<h1>$flavor</h1>";
$number_of_rows = mysql_num_rows($result);
echo "<b>$number_of_rows Flavors</b>";
$y=mysql_num_fields($result);
for ($x=0; $x<$y; $x++) {
echo mysql_field_name($result,$y)."<br>";
}
To something like this,,
Code: Select all
echo "<h1>$flavor</h1>";
while ($data = mysql_fetch_assoc($result))
{
echo $data['fieldNameOne'] . "<br />";
echo $data['fieldNameTwo'] . "<br />";
}
That should steer you in the right direction.