mysql help with a php frontend

Soldato
Joined
1 Dec 2004
Posts
22,552
Location
S.Wales
Basically im in the middle of creating a website with a mySQL database attached, i want to use a PHP frontend to allow communication between the website and the database.

Im using SQLyog enterprise which is a GUI based programme that allows me to manage the database and i am also using PHP script in my html files to hold the PHP stuff for the database.

If you go on

www.caldicot-pc-helpdesk.co.uk/fcv/index.htm

and have a look though the menu, what i want to do is attach databases to the "Up & Coming" section where i will have 3 seperate tables assigned to each sub-menu I.E. Videos, DVD, Games.

And also on the rental catalogue menu item i want a php script to load up a new page and display tables from the database which will act as the departments of the catalogue (dvd, games, vids) etc, then when the link is clicked it will refresh the page and load the contents of that table (department) onto the page.

at the moment the furthest iv managed to suss out on my own is how to display the contents of a table onto the page, and thats it.

How would i go about doing this then? my main prority at the moment is to be able to display the table names on the page as departments (which link to another page which will display the contents of that table).

Thanks
 
From what you've said it sounds like you don't know how to display the DB information in a nice HTML format?

When the link is clicked you would have it link to another page

e.g. clicking a DVD link goes to department.php?dept=dvd
 
If you know how to display the contents of a table in a page, then make one page for each of the three sections and change the table you select data from in each. This is a crap way of doing it but it'll work, and doesn't involve you learning any more.

Then once that works, we can let the fun stuff of Doing It In A Cool Way begin :)
 
Beansprout said:
If you know how to display the contents of a table in a page, then make one page for each of the three sections and change the table you select data from in each. This is a crap way of doing it but it'll work, and doesn't involve you learning any more.

Then once that works, we can let the fun stuff of Doing It In A Cool Way begin :)

Iv played around before and yes, iv been able to write a php script that is embedded into the html file which does a basic display output from a table..

But when the rental catalogue is clicked on the menu, this will open a page, it wil display a list of departments (a list of the tables in the database) then when a department is clicked (when a table link is clicked) display the items in that table in the content div.

But i want to somehow keep the department list on the screen, so maybe i need to add another div?

Do you get where i am coming from?
 
Beansprout said:
If you know how to display the contents of a table in a page, then make one page for each of the three sections and change the table you select data from in each. This is a crap way of doing it but it'll work, and doesn't involve you learning any more.

Then once that works, we can let the fun stuff of Doing It In A Cool Way begin :)


I was going to do this as it would be good enough, i could add submenu's in the menu then to link to the 3 pages..But i wanted to know how much more work would need to be done to get what i said in my previous post ^^
 
Okeys - post up the code which will do one of the pages then we'll work on how to adapt it really neatly to work for the others, too :)

The easiest way to post long PHP/HTML sections is to rename the file to .phps on the server, then it loads as highlighted source code in a browser window, and you can edit as normal then rename to .php for the server to parse it again :)
 
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>


<head>
<script type="text/javascript" src="drop.js"></script>
<link href="style2.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>First-Choice-Video.co.uk</title>
</head>




<body>


<div id="container">

<div id="banner"></div>

<div id="navigation"> 

<ul id="nav">

  <li><a href="index.htm">Home</a>
  </li>

  <li><a href="index2.htm">About Us</a>
  </li>

<li>Up & Coming
    <ul id="nav">
      <li><a href="index3.htm">Video</a></li>
      <li><a href="index4.htm">DVD</a></li>
      <li><a href="index5.htm">Games</a></li>
    </ul id>
</li>

<li><a href="index6.htm">Rental Catalogue</a>
</li>

<li>Stores 
    <ul id="nav">
      <li><a href="index7.htm">Coalville<a></li>
      <li><a href="index8.htm">Redditch</a></li>
      <li><a href="index9.htm">Solihill</a></li>
	  <li><a href="index10.htm">Tamworth</a></li>
    </ul id>
</li>

<li><a href="index11.htm">Contact Us</a>
</li>

</ul id>
</div id>

<div id="content">






</div id>

<div id="footer">
</div id>

</div id>



</body>



</html>


there you go that is a basic xhtml template i am using for my pages..

If you are refering to the PHP code i havnt written it yet, im using a template php source code from a tutorial on the net but i need to adapt it to fit my database, table and table fields on my test db at the moment..All this does is simply print out the items in the table..

Code:
<?
$username="username";
$password="password";
$database="your_database";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;
while ($i < $num) {

$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");

echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>";

$i++;
}

?>

that is simply embedded into the html document then

:)

Thanks for the help guys, really appritiate it
 
Last edited:
Right - first task is to rename all the files to .php so the server will parse them :)

And also on the rental catalogue menu item i want a php script to load up a new page and display tables from the database which will act as the departments of the catalogue (dvd, games, vids) etc
Assuming the departments don't change often, you can just use normal HTML links.

For the actual tables, do you literally want to take the rows from a table and print them all, with no different formatting for each?

If that's the case then it's easy to write a function which will loop through a result set and print out the results in a table. For example, you tell it which table you want to get results from and it queries that table then spits out all the results in a standard format.

If each table requires different formatting (for example maybe some columns are bold or hyperlinks, etc) then it's better (clearer) to write each part separately, so they can be individually customised :)
 
Beansprout said:
Right - first task is to rename all the files to .php so the server will parse them :)


Assuming the departments don't change often, you can just use normal HTML links.

For the actual tables, do you literally want to take the rows from a table and print them all, with no different formatting for each?

If that's the case then it's easy to write a function which will loop through a result set and print out the results in a table. For example, you tell it which table you want to get results from and it queries that table then spits out all the results in a standard format.

If each table requires different formatting (for example maybe some columns are bold or hyperlinks, etc) then it's better (clearer) to write each part separately, so they can be individually customised :)



Ok, so i will use .php instead of .htm extensions for the pages i am planning to display the database output onto.

The plan is that only the current products in stock (its a rental store) will be displayed on the database, so at the most all i will need it to do is to display all the entries within a table on screen when a department is selected, i will later be adding a static form somewhere which will act as a search box which will query the database with what ever is typed in and it will throw out the results onto its own page.

Formatting the tables and more precise the fields would be good for me to know as i want certain parts to stand out (bold, linked etc) and i also want the options of adding product images (is this done through the html, css, php the database itself?).

Thanks for your help mate :)
 
Back
Top Bottom