|
|
#1 (permalink) |
|
inspired to dream
Join Date: Mar 2003
Location: Raleigh, NC
Posts: 341
|
PHP database querys?
Ive figured out how too connect, and how to print something with:
Code:
<?php
/* Connecting, selecting database */
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die("Could not connect : " . mysql_error());
echo "Connected successfully";
mysql_select_db("my_database") or die("Could not select database");
/* Performing SQL query */
$query = "SELECT * FROM my_table";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
/* Printing results in HTML */
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($link);
?>
This catagory is phpbb_posts_text(holds the text/post name) and phpbb_posts(holds post ID poster ID etc.). Then phpbb_users has the user id, which is the same as the poster ID. Im not sure how to make it say the Title, the date, the poster, and then put the text under that. |
|
|
|
|
|
#2 (permalink) |
|
Registered User
Join Date: Sep 2002
Posts: 824
|
Re: PHP database querys?
Code:
<?php
/* Performing SQL query */
$query = "SELECT * FROM my_table";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
/* Printing results in HTML */
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
1) The statement Code:
$line = mysql_fetch_array($result,MYSQL_ASSOC) 2) Now, u call with MYSQL_ASSOC it means it will return the result with associative indexes, i.e, u can access the column elements like this Code:
$col1 = $ line["Title"]; 3) If u have multiple columns then using inner for loops is really not gr8 idea here is example on how i extract it(there can be better way i am newbie started two days ago) Code:
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
printf("Name : %s <br>\n",$row["name"]);
printf("Hall : %s <br>\n",$row["hall_nm"]);
printf("Room : %s <br>\n",$row["room"]);
printf("Hall dues : %d <br>\n",$row["dues"]);
}
__________________
We all are practical in our interests but, idealist when it concerns others.... |
|
|
|
|
|
#4 (permalink) | |
|
Da House Nerd
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
|
Quote:
then user Asterix great post to get it on the page.
__________________
Linux virusscanner detected a virus: Windows 95 ... delete [Y/n] y ~ ~ :wq |
|
|
|
|
|
|
#5 (permalink) | |
|
Registered User
Join Date: Oct 2003
Location: United Kingdom
Posts: 186
|
Re: PHP database querys?
Quote:
$db = mysql_connect(localhost, user, pass); mysql_select_db(database); $sql = mysql_query("SELECT * FROM table WHERE something"); echo mysql_error(); GTG, but i post back later. |
|
|
|
|
|
|
#6 (permalink) | |
|
Da House Nerd
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
|
Re: Re: PHP database querys?
Quote:
__________________
Linux virusscanner detected a virus: Windows 95 ... delete [Y/n] y ~ ~ :wq |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|