Listing MySql Database Entries

I have a PHP script that contains the following code. It's purpose is to select and show records from a database table named 'streets_articles' all those records whose 'article_id' is zero. Running this code gives the output:

0011

This is because there are two articles with the id 0 and two with the id 1. What I want to be produced is:

0011
00

Because the 'if' statement says if the id is 0, print the id again. What seems to happen is the first print statement works fine, but for some reason when the 'if' clause is reached, the article_id field doesn't have a zero in it.

Any ideas on how to make this work?

The second thing I want to do is only to display the first four records in the table that have an index of 0. Is this difficult?

Thanks

HERE IS THE CODE:

$str_requete = "SELECT page_id,article_id,article_type,page_type,page_text,page_img,article_title,article_date,articleimage FROM streets_articles ORDER BY article_date DESC";
 
$result_articles = mysql_query ($str_requete,$ezine_db) or ezine_mysql_die();

while ($articleDb =mysql_fetch_object($result_articles))
{

   print($articleDb->article_id);

   if($articleDb->article_id = 0) {

   print($articleDb->article_id);

   }
}
mi5Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VGRCommented:
of course. Classical Pascal/BASIC guys error :D

you wrote an assignation, not a test

test operator for equality is == not =

so :

$str_requete = "SELECT page_id,article_id,article_type,page_type,page_text,page_img,article_title,article_date,articleimage FROM streets_articles ORDER BY article_date DESC";

$result_articles = mysql_query ($str_requete,$ezine_db) or ezine_mysql_die();

while ($articleDb =mysql_fetch_object($result_articles))
{

  print($articleDb->article_id);

  if($articleDb->article_id == 0) { // please note that this block {} is useless for one line only in the "then"

  print($articleDb->article_id);

  }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cybertech_skCommented:
i would like suggest you to use, this form of writing in php and c++ too:

if(0 == $articleDb->article_id)
{
   print($articleDb->article_id);
}

it's better to find this mistakes and it's safer too
0
VGRCommented:
yes but no, this a "pis-aller".
if the language was using "natural" syntax and operators, it would be better...

like

if $articleDb->article_id=0 then {
  $articleDb->article_id := 1; // change to 1
} else {
}

silly parentheses (LISP influence ? :D ), == and = just make things more complexe than they should be. Moreover, ||, &&, & are totally confusing. Thanks God, the PHP people have left "normal" operators AND, OR and NOT ;-)

0
mi5Author Commented:
Thanks a lot - my stupidity earns you some easy points!! I should have remembered from my dabbles with Java. You're right about the Basic bit - I mainly use VB, so I was reading through the code again and again and just not seeing the mistake.

Anyway, the program works fine. Cheers.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.