This is a discussion on if $(action) { doesnt work within the PHP General forums, part of the PHP Programming Forums category; Hello, For lots of you this might be a simple question, but i lost sweat and tears searching for the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello,
For lots of you this might be a simple question, but i lost sweat and tears searching for the answer. I want to show some newsrecords from a database. But when i click on a link with action="all" all the records have to show. Problem is that when i dont give action in my tag it says variable action is not declared. Strange is that i start my IF with if ($action) { I give you code under this, if someone could help me i would be very gratefull. <?php if ($action) // als er een actie ondergaan wordt { if ($action=="all") { $SQL_statement="SELECT * FROM nieuws ORDER BY news_id DESC"; $resultset=mysql_query($SQL_statement); while ($data=mysql_fetch_array($resultset)) { echo "<strong>".$data['news_date']."</strong><br/>"; echo $data['news_main']."<br/><hr/>"; } } else { $SQL_statement="SELECT * FROM nieuws ORDER BY news_id DESC"; $resultset=mysql_query($SQL_statement); while ($data=mysql_fetch_array($resultset)) { echo "<strong>".$data['news_date']."</strong><br/>"; echo $data['news_main']."<br/><hr/>"; } } } else { $SQL_statement="SELECT * FROM nieuws ORDER BY news_id DESC"; $resultset=mysql_query($SQL_statement); while ($data=mysql_fetch_array($resultset)) { echo "<strong>".$data['news_date']."</strong><br/>"; echo $data['news_main']."<br/><hr/>"; } } mysql_close(); ?> |
|
|||
|
Hi,
Try wrapping the variable $action with the isset() function. Like so... if(isset($action) Regards, Kieran. vinnie wrote: > Hello, > > For lots of you this might be a simple question, but i lost sweat and > tears searching for the answer. > I want to show some newsrecords from a database. But when i click on a > link with action="all" all the records have to show. Problem is that > when i dont give action in my tag it says variable action is not > declared. Strange is that i start my IF with if ($action) { > > I give you code under this, if someone could help me i would be very > gratefull. > > <?php > if ($action) // als er een actie ondergaan wordt > { if ($action=="all") > { > $SQL_statement="SELECT * FROM nieuws ORDER BY news_id DESC"; > $resultset=mysql_query($SQL_statement); > while ($data=mysql_fetch_array($resultset)) > { > echo "<strong>".$data['news_date']."</strong><br/>"; > echo $data['news_main']."<br/><hr/>"; > } > } else > { > $SQL_statement="SELECT * FROM nieuws ORDER BY news_id DESC"; > $resultset=mysql_query($SQL_statement); > while ($data=mysql_fetch_array($resultset)) > { > echo "<strong>".$data['news_date']."</strong><br/>"; > echo $data['news_main']."<br/><hr/>"; > } > } > } else { > > $SQL_statement="SELECT * FROM nieuws ORDER BY news_id DESC"; > $resultset=mysql_query($SQL_statement); > while ($data=mysql_fetch_array($resultset)) > { > echo "<strong>".$data['news_date']."</strong><br/>"; > echo $data['news_main']."<br/><hr/>"; > > } > } > mysql_close(); > ?> |