Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using list to constuct page

Status
Not open for further replies.

jefargrafx

Instructor
May 24, 2001
273
US
I'm using the list (like array) to pull data and make a page.

for ($i=0;$i<$count;$i++) {
list($picid,$propid,$desc,$picSortOrder) = db_fetchrow($query);
echo "picid= ".$picid." picSortOrder= ".$picSortOrder."<br>";
}

I then pass this info to a script to change the display order of some photo. MOving them up or down based on the picsortorder. My trouble come in when trying to know the picid or the photo above or below the one I'm moving.

I need to update the database to switch position.

list will make a list say:

1
2
3
4

I want to change 4 and 3, but sometime 3 and be 2 or 1 and I need to know how to get LIST to tell me the varable above 4 reguardless.

hope I didn't confuse ya

any help would be great

thanks

jef
 
i do not understand the question.

however it strikes me that you should consider first using non-abstracted functions such as mysql_fetch_* and refraining from using the list() construct.

i.e. simplify your life whilst debugging your script. then add layers of complexity when each simple structure is fixed up.
 
agreed,

sorry,

list($picid,$propid,$desc,$picSortOrder) = mysql_fetch_row($query);

produces an array, right?

I need to know the keys to that array above and below the record I need to change.



jef
 
no, it does not produce an array. it produceds four discrete variables.

this is the normal way of looping over a recordset

Code:
$result = mysql_query("select * from table");
while ($row = mysql_fetch_assoc($result)) {
  //do something with $row.  
}

$row, above, will have the field names as its keys and the values as its values. you can access the keys like so

Code:
foreach ($row as $key=>$val){
 "key is $key val is $val <br/>";
}
 
okay, thanks for the info,

I'm moving into real array world now.

$result = mysql_query("select * from property_pictures where propid='$propid' order by picSortOrder asc");
while ($row = mysql_fetch_assoc($result)) {
//do something with $row.
echo $row["picid"]."<br>";
}

foreach ($row as $key=>$val){
echo "key is $key val is $val <br/>";
}

the while does in deed get the pricid and put them inorder, however the foreach statement is not returning the key values, am I doing something worng.

Also, them I get the keys, how do I assign a variable to them?

let me know and thanks

jef
 
a variable is already assigned to the key, that's the nature of the array.

it's not working as you anticipate because you are putting the foreach loop outside of the while loop. by the time the cursor gets to the foreach, the value for $row is null. put the code back within the while and see what you get.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top