Page 1 of 1

basic variable problem

Posted: Fri Dec 27, 2002 9:24 pm
by seiferlukem

Code: Select all

$sql=mysql_query("SELECT * FROM useritem WHERE userid='$verified_id'");
$sql=mysql_fetch_array($sql);
print"<table width=80% border=1 cellspacing=0 cellpadding=0>";
$count=1;
$first=first;
if($sql[item1]!=0){
$first.$count=$sql[item1];
$count++;
}
if($sql[item2]!=0){
$first.$count=$sql[item2];
$count++;
}
Well what this is supposed to do is make a list of items such as 1 2 3 in a 2 x something formation.
[first][second]
[third][fourth]
[fifth][sixth]
[eighth][nineth]

itll ignore empty results because it increments all variablenames once a result has been registered.
My problem is that i cant make the variable name how i want it :

$first.$count=$sql[item2];

I want it too make a variable called $first(number stored in count vairable) to equal the sql querys items for example

$count=43
$first($count)=$sql[item2]
($first43=$sql[item2])
echo $first43

(displays what was in $sql[item2]'s contents)

Any help would be great thanks.

Posted: Sat Dec 28, 2002 5:04 am
by Elmseeker
Not exactly sure what you want here but to set your initial $count value you could use:

Code: Select all

$mysql_num_rows($sql);
As for the rest a while is probably better than using all those if's and you can set it up so that it resets itself every 2 rows, I did somethin similar on one of my sites:

Code: Select all

<?
$query = "SELECT * FROM public_info";
$result = mysql_db_query("$dbase",$query);
echo "<table ALIGN=CENTER width="90%" cellspacing="0" cellpadding="0" border="0"><TR>";
/* print */
while($row =mysql_fetch_array($result)){
$i = $row[0];
echo "<TD ALIGN=CENTER><A HREF="".$PHP_SELF."?id=".$i."">".$row["imm_name"]." </A></TD>";
if ( $i == 5 || $i == 10 || $i == 15 || $i == 20 || $i == 25 || $i == 30 ) {
echo "</TR><TR>";
}
}
echo "</TR></TABLE>";
?>
Hope this helps, it is probably not the cleanest code in the world but it's one of the first things I ever wrote while learning PHP. :)