Reputation: 557
I'm trying not to repeat code. Is there any way to get this working so I don't have to write out the code three times for the three people? Forgive my ignorance: I'm a beginner.
$c1 = "Rufus T Firefly";
$c2 = "Chicolini";
$c3 = "Pinky";
for ($i=1; $i<=3; $i++){
$result = mysqli_query($dbc, ' SELECT * FROM voters WHERE choice = "'. $c($i).'" ');
//create table...
}
Upvotes: 1
Views: 140
Reputation: 219814
Use IN()
$sql = "SELECT * FROM voters WHERE choice IN('Rufus T Firefly', 'Chicolini', 'Pinky')"
$result = mysqli_query($dbc, $sql);
Now no loops or arrays needed (to generate your query).
Upvotes: 4