-2

i have SQL query :

SELECT countryCode FROM itins_countries WHERE (itinID = 5);
$countriesIndex = mysql_fetch_array($countriesQuery);

now, in another art of my code I would like to run on the "$countriesIndex" and print all the values it contain ("countryCode");

how can i do that?

Sunil Rajput
  • 960
  • 9
  • 19
Roi
  • 49
  • 8
  • Do You have a reason to use mysql_* functions? It is legacy code removed from PHP some time ago. https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Michas Jul 17 '17 at 09:21
  • Not all server support the new commands... – Roi Jul 17 '17 at 09:33
  • If You need answer that need legacy PHP code, You have to state this in Your question. This question looks like from the PHP4 era. It was over 10 years ago. It is very unfortunate to have to use so outdated system. – Michas Jul 17 '17 at 11:53

3 Answers3

1
while($row = mysql_fetch_array($countriesQuery)){
     echo $row['column_name'];
     ///same for other columns
}

you can use the while loop to loop until all the array element has been printed

Exprator
  • 26,992
  • 6
  • 47
  • 59
0

try this....

echo "<pre>";print_r($countriesIndex);
GYaN
  • 2,327
  • 4
  • 19
  • 39
  • No, i want to run loop that print / check the values – Roi Jul 17 '17 at 09:14
  • 1
    Thank you for this code snippet, which may provide some immediate help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its educational value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with similar, but not identical, questions. Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Jul 17 '17 at 13:53
0

mysql_connect is deprecated...you can use mysqli_connect.

    $mysqli = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
    if (mysqli_connect_errno($mysqli)) {
        trigger_error('Database connection failed: '  . mysqli_connect_error(), E_USER_ERROR);
    }
    mysqli_set_charset($mysqli, "utf8");

    $sql = "SELECT countryCode FROM itins_countries WHERE (itinID = 5)";
    $result = mysqli_query($mysqli, $sql);
    $countries = [];
    while($row = $result->fetch_assoc())
    {
        $users_arr[] = $row;
    }
    $result->close();
    print_r($users_arr);
Rahul Dhande
  • 483
  • 5
  • 9