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 » Sat Jun 23, 2007 10:39 pm
I am looking to list the column names that have values that are not null in a certain row.
What I have so far is the fallowing
Code: Select all
<?php
error_reporting(0);
function mysqls_sad()
{
echo "MySQL said: Error: " . mysql_errno() . ' - ' . mysql_error();
exit();
}
if (!is_resource(($dbcon = mysql_connect("db949.perfora.net", "dbo207711380", "###pass##"))))
{
mysqls_sad();
}
if (!mysql_select_db('db207711380', $dbcon))
{
mysqls_sad();
}
$flavor = $_GET["flavor"];
$sql = 'SELECT * FROM `flavors` WHERE `flavor`=\'Apple\' LIMIT 0, 30 ';
if (false === ($result = mysql_query($sql)))
{
mysqls_sad();
}
while($brand = mysql_fetch_field($result))
{
if ($brand->name != 'flavor_id' && $brand->name != 'flavor' && $brand->name != 'desc' && $brand->not_null!='1')
{
echo $brand->name;
echo "<br/>";
}
}
?>
what I have it doing so far is displaying the columns name, while taking out those that I dont want to display(like id and such). But then I dont know how to check to see if that value is/isnt Null.
Do you guys have any idea or am I on the completely wrong track.
Thanks you guys have been so helpful with this stuff.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat Jun 23, 2007 10:44 pm
To test is something is not null you can use..
Code: Select all
// ensure it is anything BUT null
$x !== null
// check if it is an empty string, null, 0 or boolean false
empty($x)
slomotion
Forum Newbie
Posts: 13 Joined: Fri Jun 22, 2007 9:15 pm
Post
by slomotion » Sat Jun 23, 2007 11:13 pm
ok so I thought I was doing it right but got an error message
a revamp to my coding
Code: Select all
<?php
error_reporting(0);
function mysqls_sad()
{
echo "MySQL said: Error: " . mysql_errno() . ' - ' . mysql_error();
exit();
}
if (!is_resource(($dbcon = mysql_connect("db949.perfora.net", "dbo207711380", "x6cFkX.R"))))
{
mysqls_sad();
}
if (!mysql_select_db('db207711380', $dbcon))
{
mysqls_sad();
}
$flavor = $_GET["flavor"];
$sql = 'SELECT * FROM `flavors` WHERE `flavor`= `Apple`';
if (false === ($result = mysql_query($sql)))
{
mysqls_sad();
}
while($newArray = mysql_fetch_assoc($result))
{
if (empty($newArray))
{
//nothing
}
else
{
$brand = mysql_fetch_field($newArray);
echo $brand->name;
echo "<br/>";
}
}
?>
This same error message I thought I had it right but maybe not. a 1054 message.
but I dont know what is wrong with it.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat Jun 23, 2007 11:17 pm
What field are you checking?
You can add it to the query like you asked the other day. But if you want to do it in PHP you have to specify the array index.
Code: Select all
if (empty($newArray['FIELD_NAME_HERE']))
{
//nothing
}
slomotion
Forum Newbie
Posts: 13 Joined: Fri Jun 22, 2007 9:15 pm
Post
by slomotion » Sat Jun 23, 2007 11:27 pm
Dang Im still getting used to this array thing.
Im trying to check each one that comes through (if that makes sense), or all of them except the ones that I have set out.
I think I need to take a class for this stuff, I need to learn more of the rules.