Forum Moderators: coopster

Message Too Old, No Replies

using php to look up mysql database

         

humpingdan

2:01 pm on Mar 26, 2004 (gmt 0)

10+ Year Member



heres what i want to do, ive only been able to find one "good" tutorial on this so far and its quite limited so some of your input would be appreciated,

so,
i want to be able to display 8 widgets each categorized into colour,

2 blue - 2 red - 2 green - 2 yellow -

i want to link to each colour then display the contents of that colour, ie

red
----
1 widget
2 widget

and so on.....

then click a particular widget in its category and it display furthur information on that widget!
==========================================

thats what i want to do, if somebody would enjoy the chalenge of creating a suitable database structure go ahead,;)

also create php coding wud be fab-tastic! :)

but in reality i just need someone to point out some tutorials on how to look up the data and creat the best structure for my Mysql database? cutting down on duplicate content etc...

any help would be great im just really stuck, i have limited knowledge of both mysql and php, i have installed mysql phpyadmin and apache so im rareing to go!

Dan!

lorax

4:07 pm on Mar 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hoo boy. ;)

Well...you'll find a lot of tutorials that cover the skills needed to build what you want but I don't know of any that cover the specific functionality you're looking for. Developing the database structure and corresponding code go hand in hand and there are so many options that it's next to impossible for us to suggest how you should go about it. Likewise, tutorials will give you the basic concepts and a few examples but in order for you to apply it to your specific situation you'll need to just dive in and try it.

humpingdan

4:16 pm on Mar 26, 2004 (gmt 0)

10+ Year Member



<?php

// Connect to the database server
$dbcnx = @mysql_connect('mysql', 'user', 'pass');
if (!$dbcnx) {
die( '<p>Unable to connect to the ' .
'database server at this time.</p>' );
}
// Select the links database
if (! @mysql_select_db('links') ) {
die( '<p>Unable to locate the links ' .
'database at this time.</p>' );
}
echo('<p> Here are all the links in our database: </p>');

// Request the ID and text of all the links
$result = @mysql_query('SELECT id, title, link FROM links'); {

}
// Display each link
while ( $row = mysql_fetch_array($result) ) {
$linkid = $row['id'];
$linktitle = $row['title'];
$linkurl = $row['link'];

echo('<p>'.'<a href="' . $linkurl . '">' . $linktitle . '</a>'.'</p>');

}

?>

just came up with this as a basic links list!?!

is this going along the right lines, obviously long way off full website, could anyone perhaps give a run down of this?

MrSpeed

4:18 pm on Mar 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There was a nice tutorial I found that helped me get started. Just google the terms "webmonkey php mysql tutorial"

Start with the first thing you want to do and then keep building onto it.

There are a few ways to approach this. You can post to as different page to run a sql query or you can keep posting to the same page and sniff for variables.

It seems like your links are going to take on three different forms
widgets.php
widgets.php?color=blue
widgets.php?color=blue&id=3

So one way to approach this is

$color=$_GET['color'];
$id=$_GET['id'];

/* Performing SQL query */
if (strlen($id)>1){
$query="SELECT * FROM widgets WHERE id ='$id' order by widget";
}
else if (strlen($color)>1) {
$query="SELECT distinct widgetsname FROM widgets WHERE color ='$color' order by widgetsname";
}
else {
$query="SELECT distinct * widgetsname FROM widgets order by widgetsname";
}

$result = mysql_query($query) or die("Query failed : " . mysql_error());

***show results by looping through results array