Jump to content

Integration into website


Ameslee

Recommended Posts

Hope someone can help me, im new at PHP and to tell you the truth this is my very first time at integration into a website. Can someone tell me how i display stuff from my database to my website pages? I just want records from my database to be displayed. HELP please!

Thanks
Link to comment
Share on other sites

there are several ways to display data from mysql database

here's the way i do it

[code]

<?php
     $hostname = localhost;
     $username = username;
     $password = password;

     $db = mysql_connect($hostname, $username, $password) or die(mysql_error());
     $connection  = mysql_select_db("mydb", $db);

     $sql = "SELECT fname, lname FROM table_name";
     $result = mysql_query($sql, $connection);

     while ($rows = mysql_fetch_array($result))
     {
       $fname = $rows['fname'];
       $lname = $rows['lname'];

       echo $fname;
       echo $lname;
     }
?>
[/code]


i'm havent tested it..... i probably missed a semi colon somewhere .. but it should be alrite .... and a simple google search will give u lots and lots of info on using php/mysql :)
Link to comment
Share on other sites

Can't you use a database include, like include("database.inc");?
or do you use the kind of way like below?

[!--quoteo(post=365806:date=Apr 18 2006, 11:21 AM:name=devofash)--][div class=\'quotetop\']QUOTE(devofash @ Apr 18 2006, 11:21 AM) [snapback]365806[/snapback][/div][div class=\'quotemain\'][!--quotec--]
there are several ways to display data from mysql database

here's the way i do it

[code]

<?php
     $hostname = localhost;
     $username = username;
     $password = password;

     $db = mysql_connect($hostname, $username, $password) or die(mysql_error());
     $connection  = mysql_select_db("mydb", $db);

     $sql = "SELECT fname, lname FROM table_name";
     $result = mysql_query($sql, $connection);

     while ($rows = mysql_fetch_array($result))
     {
       $fname = $rows['fname'];
       $lname = $rows['lname'];

       echo $fname;
       echo $lname;
     }
?>
[/code]
i'm havent tested it..... i probably missed a semi colon somewhere .. but it should be alrite .... and a simple google search will give u lots and lots of info on using php/mysql :)
[/quote]
Link to comment
Share on other sites

include doesn't necessarily display the data, it just, like it's name implies, includes its info into the current document

and php is server code, it is parsed before it ever reaches the user, they can only see the output
[code]
<?php
echo "<h1>Hello<h1>";
?>

//displays in web source code
<h1>Hello<h1>
[/code]
Link to comment
Share on other sites

I can't get the above code to work, i have changed it to suit my purposes, here it is:

<?php
$hostname = localhost;
$username = *******_***;
$password = ********;

$conn = mysql_connect($hostname, $username, $password) or die(mysql_error());
$connection = mysql_select_db($database_conn, $conn);


$query = "SELECT name, age, gifts, about FROM Stories";
$mysql_result=mysql_query($query,$conn);

while ($rows = mysql_fetch_array($mysql_result))
{
$name = $rows['name'];
$age = $rows['age'];
$gifts = $rows['gifts'];
$about = $rows['about'];

<table>
<tr>
<td><b>Name</b><td>echo $name;
<tr><td><b>Age</b><td>echo $age;
<tr><td><b>Gifts and Talents</b><td>echo $gifts;
<tr><td><b>More about $name</b><td>echo $about;</tr>
</table>
}
?>
Link to comment
Share on other sites

i have also changed the code to this:

?php

$connect = mysql_connect("localhost","*******_***","********");

$db = mysql_select_db("Stories",$connect);

$query = "SELECT * FROM Stories";

$mysql_result = mysql_query($query);

$display_array = mysql_fetch_array($mysql_result);

echo $display_array["name"];
echo $display_array["age"];
echo $display_array["gifts"];
echo $display_array["about"];

?>
and still get this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/tafeamy/public_html/project/Klever Kids/stories.php on line 105
Link to comment
Share on other sites

Try This:

[code]<?php
$hostname = localhost;
$username = *******_***;
$password = ********;

$conn = mysql_connect($hostname, $username, $password) or die(mysql_error());
$connection = mysql_select_db($database_conn, $conn);


$query = "SELECT name, age, gifts, about FROM Stories";
$mysql_result=mysql_query($query,$conn);

echo("<table>");

while ($rows = mysql_fetch_array($mysql_result)){
echo("
<tr>
<td><b>Name</b><td>" . $rows['name'] . "
<tr><td><b>Age</b><td>" . $rows['age'] . "
<tr><td><b>Gifts and Talents</b><td>" . $rows['gifts'] . "
<tr><td><b>More about " . $rows['name'] . "</b><td>" . $rows['about'] . "</tr>");
}


echo("</table>");
?>[/code]

you cant output raw html within the <?php ?> tags, you need to echo them, also advanced warning: make sure to \ any " or ' within echos like this:

[code]<?php
echo("Foo \"Bar\"");
?>[/code]

to avoid any parse errors - sorry if the code is kinda messey, i was in a rush :)
Link to comment
Share on other sites

Thanks alot, this does work, fine.

[!--quoteo(post=365895:date=Apr 18 2006, 03:30 PM:name=Hooker)--][div class=\'quotetop\']QUOTE(Hooker @ Apr 18 2006, 03:30 PM) [snapback]365895[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Try This:

[code]<?php
$hostname = localhost;
$username = *******_***;
$password = ********;

$conn = mysql_connect($hostname, $username, $password) or die(mysql_error());
$connection = mysql_select_db($database_conn, $conn);
$query = "SELECT name, age, gifts, about FROM Stories";
$mysql_result=mysql_query($query,$conn);

echo("<table>");

while ($rows = mysql_fetch_array($mysql_result)){
echo("
<tr>
<td><b>Name</b><td>" . $rows['name'] . "
<tr><td><b>Age</b><td>" . $rows['age'] . "
<tr><td><b>Gifts and Talents</b><td>" . $rows['gifts'] . "
<tr><td><b>More about " . $rows['name'] . "</b><td>" . $rows['about'] . "</tr>");
}
echo("</table>");
?>[/code]

you cant output raw html within the <?php ?> tags, you need to echo them, also advanced warning: make sure to \ any " or ' within echos like this:

[code]<?php
echo("Foo \"Bar\"");
?>[/code]

to avoid any parse errors - sorry if the code is kinda messey, i was in a rush :)
[/quote]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.