0

I'm new to php.I tried to connect db use php mysqli and query multiple values and then assign to new variable.

Code:

<?php
$con=mysqli_connect('127.0.0.1','name','password','database name');
mysqli_query($con, "SET character_set_results=utf8,character_set_client='utf8'");
mysqli_query($con, "SET NAMES 'utf8'");
$sql="SELECT store_web,store_email,store_address1,store_city,store_state,store_zip,store_phone,store_time FROM mystore";
if ($result = mysqli_query($con, $sql)) {
  // Fetch one and one row
  while ($row = mysqli_fetch_row($result)) {
   printf ("%s (%s)\n", $row[0], $row[1]);

  }
  mysqli_free_result($result);
}

mysqli_close($con);
?>

My question is how should I modify the code so that I can assign new variable name to the value(store_web,store_email,store_address1,store_city,store_state,store_zip,store_phone,store_time) I have queried out?

for example, after query out and get the value of store_address1,$address = store_address1

William
  • 3,724
  • 9
  • 43
  • 76
  • What do you mean by "value I have queried out"? What exactly are you trying to achieve, can you give a bit more context? – El_Vanja Dec 01 '20 at 16:50
  • Thank you for your reply,I want to get the value of (store_web,store_email,store_address1,store_city,store_state,store_zip,store_phone,store_time) and assign a assign new variable to them.for example,after query out and get the value of store_address1,$address = store_address1 – William Dec 01 '20 at 16:53
  • 1
    you already have such variables. just use `mysqli_fetch_assoc()` and then you will have all variables in this form `$row['store_address1']` – Your Common Sense Dec 01 '20 at 16:54
  • @YourCommonSense thank you for your reply, I think you gives the right answer, can you post it as an answer so that I can check it?Thank you so much! – William Dec 01 '20 at 16:58
  • No need for the new answer, there are existing ones – Your Common Sense Dec 01 '20 at 17:00
  • Thank you I got it! – William Dec 01 '20 at 17:03

0 Answers0