noob nic question

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

Post Reply
orditerreur
Forum Newbie
Posts: 6
Joined: Tue Jul 12, 2005 2:37 pm

noob nic question

Post by orditerreur »

Hi everyone, to begin with, im french 8O anyway I have a prob with some newbie code, since im noob it's normal...

The thing is than i don't understand, why in the following code (isset($start)) alway return false...

I have read isset in php.net but without any succes... thank for helping me.

Code: Select all

<?php
	
if (isset($start)) 
{
	$start=$_GET["start"];
	
	$query = "SELECT * FROM inscription LIMIT " . $start . ", 1";
			
	@mysql_connect("localhost","root","") or die("Echec de connexion au serveur.");
	@mysql_select_db("form") or die("Echec de seclection de la base.");

	$result = mysql_query($query); //you should do error checking
	//display data
		
     while ($ligne = mysql_fetch_row($result)) 
     {
        echo "<BR>";
        /* foreach() passe en revue toutes les valeurs d'un tableau. */
        foreach ($ligne as $value) echo "$value <BR>";
     }
	echo "<br />";	 
	//this code was wrong, I did not have the second query. Thanks to Plaggy Pig.
	// need another query to get the total amount of rows in our table
	$query = "SELECT count(*) as count FROM inscription";
	$result = mysql_query($query);
	$row = mysql_fetch_array($result);
	$numrows = $row['count'];
	if($start > 0)
	   echo "<a href=\"" . "erreur.php" . "?start=" . ($start - 1) . "\">Previous</a> \ ";
	if($numrows > ($start + 1))
	   echo "<a href=\"" . "erreur.php" . "?start=" . ($start + 1) . "\">Next</a><BR>";
}
else
{	
echo "var pas seter";
	$start=0;
	
	$query = "SELECT * FROM inscription LIMIT " . $start . ", 1";
			
	@mysql_connect("localhost","root","") or die("Echec de connexion au serveur.");
	@mysql_select_db("form") or die("Echec de seclection de la base.");

	$result = mysql_query($query); //you should do error checking
	//display data
		
     while ($ligne = mysql_fetch_row($result)) 
     {
        echo "<BR>";
        /* foreach() passe en revue toutes les valeurs d'un tableau. */
        foreach ($ligne as $value) echo "$value <BR>";
     }
	echo "<br />";	 
	//this code was wrong, I did not have the second query. Thanks to Plaggy Pig.
	// need another query to get the total amount of rows in our table
	$query = "SELECT count(*) as count FROM inscription";
	$result = mysql_query($query);
	$row = mysql_fetch_array($result);
	$numrows = $row['count'];
	if($start > 0)
	   echo "<a href=\"" . "erreur.php" . "?start=" . ($start - 1) . "\">Previous</a> \ ";
	if($numrows > ($start + 1))
	   echo "<a href=\"" . "erreur.php" . "?start=" . ($start + 1) . "\">Next</a><BR>";
}
?>
d11wtq | Please use

Code: Select all

tags when posting PHP code [/color]
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

That is because you $start is not set at the point you are testing it.

Code: Select all

<?php 
if (isset($start)) 
{ 
$start=$_GET["start"];
/// and so on
orditerreur
Forum Newbie
Posts: 6
Joined: Tue Jul 12, 2005 2:37 pm

Post by orditerreur »

I forgot to mention than this is the next line than I believe should send the var $start

Code: Select all

echo "<a href=\"" . "erreur.php" . "?start=" . ($start + 1) . "\">Next</a><BR>";
and

Code: Select all

echo "<a href=\"" . "erreur.php" . "?start=" . ($start - 1) . "\">Previous</a> \ ";
hmm i belive when you clik on a link the page reload and you can get the var $start with GET isn't?
Last edited by orditerreur on Tue Jul 12, 2005 3:20 pm, edited 2 times in total.
orditerreur
Forum Newbie
Posts: 6
Joined: Tue Jul 12, 2005 2:37 pm

Post by orditerreur »

how i set it and where, im confuse
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

but unless you set start above the isset() function, it won't be set and therefore the if condition won't be met.
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

When you click the link $_GET['start'] is being set. Maybe you should test it?

And please, there is a button which says 'PHP'. Take advantage of it. It sure makes life a bit easier for everyone.
orditerreur
Forum Newbie
Posts: 6
Joined: Tue Jul 12, 2005 2:37 pm

Post by orditerreur »

hmmm I have set it but when it reload the page, it take again the 0 as value.

Code: Select all

<?php
$start=0;
if (isset($start) && $start != 0)
{
	$start=$_GET["start"];
I dont think it will work coz the server will alway take my first seting.. $start=0...

Thank for the "php" buton tip
Last edited by orditerreur on Tue Jul 12, 2005 3:29 pm, edited 5 times in total.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

if he has register_globals off, then just using isset($start) wont' work for $_GET['start']
orditerreur
Forum Newbie
Posts: 6
Joined: Tue Jul 12, 2005 2:37 pm

Post by orditerreur »

hmm like 6 hours I work on this...

Someone as a clue how to cast the var $start
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

just use isset($_GET['start'])
orditerreur
Forum Newbie
Posts: 6
Joined: Tue Jul 12, 2005 2:37 pm

Post by orditerreur »

you are right, damm right: this is working

This is where i see how noob I am.... shame on me...

Thank guys
Post Reply