php sql, assign variable to each row of an array -
i have mysqli_query pulls 3 columns , 10 rows table. assign variable each row of query. 10 seperate querys , assign each variable, assumed frowned upon. (note: connection info in seperate file , not shown here).
<?php $playoffseedings = mysqli_query($con, "select playoffseed, ttname, ttsuid standings ttsuid = $season_view , playoffseed > 0 order playoffseed limit 10"); $seedings = array($playoffseedings); foreach($seedings $ps){ $num_rows = 1; while($row = mysqli_fetch_array($ps)){ $num_rows++; echo $row['playoffseed'].$row['ttname']; echo "<br>"; }} ?>
the foreach used above works fine , returns 10 rows of data queried. that's cool. need able display different rows in different places on page. thought assigning each row different variable work well.
i tried adding such assign variable each row i'd have 10 different variables $seed1, $seed2, $seed3..., each $seedx array of playoffseed, ttname, , ttsuid.
foreach($seedings $ps){ $num_rows = 1; while($row = mysqli_fetch_array($ps)){ $num_rows++; $seed$num_rows = $row[$num_rows]; }}
i'd know how above, also, confused on journey why couldn't echo row array using
echo $seedings[1]; echo $seedings[7]['playoffseed'];
why wouldn't 'echo $seedings[1];' return result of second row of $seedings array? got blank.
and why wouldn't 'echo $seedings[7]['playoffseed'];' return playoffseed of 8th row? again, blank.
i felt 2 questions tied because thought either refer data wanted later either variable (ie. $seed3), or possibly refer data need using index (keys?) of array (ie $seedings[7]['playoffseed']).
first post! help. find need after few hours of searching. stuck on 1 after few days of looking.
edit (in attempt clarify): query returns table (multidimensional array?) this...
ttsuid ttname playoffseed 1993 buffalo 1 1993 miami 2 1993 detroit 3 1993 denver 4 1993 chicago 5 ...and on. 10 rows total
after calling query i'd set variables ($seedx) such this...
$seed1 = (1993, buffalo, 1) $seed2 = (1993, miami, 2) $seed3 = (1993, detroit, 3) ...and on until $seed10
so each $seedx variable array pulled multidimensional array. that's pretty it.
alternatively make 10 separate querys database , increment 'and playoffseed = 1' each time such this...
$seed1 = mysqli_query($con, "select playoffseed, ttname, ttsuid standings ttsuid = $season_view , playoffseed = 1"); $seed2 = mysqli_query($con, "select playoffseed, ttname, ttsuid standings ttsuid = $season_view , playoffseed = 2");
but didn't think querying database 10 times way go.
in end hoping 10 variables ($seed1, $seed2,...$seedx) each array includes (ttsuid, ttname, playoffseed).
still not sure how want store data,but hope helps you
$playoffseedings = mysqli_query($con, "select playoffseed, ttname, ttsuid standings ttsuid = $season_view , playoffseed > 0 order playoffseed limit 10"); while($row = mysqli_fetch_assoc($playoffseedings)) { $seed[$row['ttname']] = $row['ttsuid']; $seed[$row['playoffseed']] = $row['ttsuid']; }
this have data below
(for example)
$seed['ttname123']= ttsuid123 $seed['playoffseed123']= ttsuid123 $seed['ttname456']= ttsuid456 $seed['playoffseed456']= ttsuid456 ........ ......
Comments
Post a Comment