Codes here !
Moderators: macek, egami, gesf
by bennos89 » Fri Oct 12, 2012 9:07 am
Hi,
I still find php 5 rather confused. Their documentation is hard to understand.
Ok back to the topic. How do I retrieved information from the database in rows forms
Let say I got
Id. Name
1. Abc
2. Jane
How do I store this information into my array? Using mysqli
$idarray= new array()
$idarray[0]= 1
-
bennos89
- New php-forum User

-
- Posts: 4
- Joined: Wed Sep 12, 2012 4:57 pm
by seandisanti » Fri Oct 12, 2012 9:34 am
Here's documentation to get you started:
http://us1.php.net/manual/en/mysqli.quickstart.phphere's an object orient example :
- Code: Select all
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT CURRENT_USER();";
$query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";
/* execute multi query */
if ($mysqli->multi_query($query)) {
do {
/* store first result set */
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_row()) {
printf("%s\n", $row[0]);
}
$result->free();
}
/* print divider */
if ($mysqli->more_results()) {
printf("-----------------\n");
}
} while ($mysqli->next_result());
}
/* close connection */
$mysqli->close();
?>
and a procedural one :
- Code: Select all
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT CURRENT_USER();";
$query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";
/* execute multi query */
if (mysqli_multi_query($link, $query)) {
do {
/* store first result set */
if ($result = mysqli_store_result($link)) {
while ($row = mysqli_fetch_row($result)) {
printf("%s\n", $row[0]);
}
mysqli_free_result($result);
}
/* print divider */
if (mysqli_more_results($link)) {
printf("-----------------\n");
}
} while (mysqli_next_result($link));
}
/* close connection */
mysqli_close($link);
?>
-
seandisanti
- php-forum Fan User

-
- Posts: 679
- Joined: Mon Oct 01, 2012 12:32 pm
Return to mySQL & php coding
Who is online
Users browsing this forum: No registered users and 1 guest