Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically create variables in while loop based on sql query
    primarykey
    data
    text
    <pre><code>SELECT a.uid, a.name_f, a.name_l, b.position FROM users a, room_members b WHERE a.uid = b.userid AND b.room_id=$room_id </code></pre> <p>I have the above query that selects the name, uid, profile pic and position of a certain user based on the room_id, and I want to return a while loop that assigns the following variables to any positions that returns in my query, dynamically. </p> <pre><code>$position1_name_f $position1_name_l $position1_uid $position1_pic $position2_name_f $position2_name_l $position2_uid $position2_pic </code></pre> <p>So for example, if positions 4 and positions 8 are the only ones among the data returned, it would return the following variables and I would be able to use theses variables freely in my script.</p> <pre><code>$position4_name_f $position4_name_l $position4_uid $position4_pic $position8_name_f $position8_name_l $position8_uid $position8_pic </code></pre> <p>There would be a maximum of 10 positions at the most. I desperately need those variables because I use them heavily with the layout of the site and there's no way for me to do a simple while loop echo; otherwise, everything would be a lot easier. </p> <p>I tried using variable variables and I also tried deploy a counter but couldn't get either to work. </p> <p>I started the following query and would really appreciate some help. Thanks</p> <pre><code>$room_members=mysql_query("SELECT a.uid, a.name_f, a.name_l, b.position FROM users a, room_members b WHERE a.uid = b.userid AND b.room_id=$room_id"); while($members_sql=mysql_fetch_array($room_members)) { //Need some dynamic variables here... } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload