Jump to content

MySQL driven website


Cabbage

Recommended Posts

Hi guys, Im new to PHP/MySQL and this forum so go easy :)

 

A friend and I are experimenting with a website we're building.

 

http://www.guernseytraders.com/home_2ad.php  (this is just an example of how one page might look)

 

The idea being that theres going to be (hopefully) a few companies on this website and the website will be split into different categories. For example there might be a tradesman page where I want a list of all the local tradesmen. We've decided to put the companies and there data into a MySQL database and have PHP call up each company ad into the different boxes. It looks like I'm going to have to customise the code for each individual advert? Is it worth doing in a database or would I be better off flatcoding everything into HTML?

 

The PHP I'm using looks something like this...

 

<div class="adtextbox">

<?php

$con = mysql_connect("xxxxx.net","xxxxx,"xxxxx");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("xxxxxx", $con);

 

$result = mysql_query("SELECT * FROM Companies WHERE Number = '2'");

 

echo "<table border='0'>

";while($row = mysql_fetch_array($result))

  {

  echo "<tr>";

  echo "<td>" . $row[6] . "</td>";

  echo "<td>" . $row[3] . "</td>";

  echo "</tr>";

  }

echo "</table>";mysql_close($con);

?>

 

</div>

 

Thanks

Link to comment
Share on other sites

hi this is very simple.

 

 

hardcode the links

 

<a href="page.php?id=tradesman">Tradesman</a>

 

then

 

$url = @$_POST['id'];

 

then in ur select statement instead of searching for 2

 

 

$result = mysql_query("SELECT * FROM Companies WHERE Catergory= '". $url ."'");

 

catergory being replaced with w/e field u need it to be replaced with.

 

that way u dont have to have mutiple pages u can call 1 page and not 30. thus being dynamic

Link to comment
Share on other sites

$_POST method???

 

No, it is opposite...

 

url -> $_GET

 

form -> $_GET, $_POST

 

I belive that php manual will help...

 

I would do id like this. Without direct link betwen url and sql query:

 

if you have link:

<a href="page.php?id=1">Tradesman</a>
<a href="page.php?id=2">Some other</a>

<?php

switch ($_GET['id']) {
case 1:
$url = "tradesman";
break;
case 2:
$url = "some_other";
break;
default:
$url = "default";
break;
}


$result = mysql_query("SELECT * FROM Companies WHERE Catergory= '". $url ."'");

 

BTW, this has to work!!!

Link to comment
Share on other sites

ugh. i just did this last week for someone. and the $_GET did not work for a hardcoded url @$_POST worked and i went for hours trying to figure out why my data would not show then i switched the $_GET to $_POST and BLAM it worked.

Link to comment
Share on other sites

??? ??? ??? ???

$_POST is used for form submitting using POST Method

 

$_GET is used of form submitting with get method and for url variables

 

you can use

 

$_REQUEST to get variables from both methods

 

you cannot get the values (array)of multiple combo box using $_POST  you need to use $_REQUEST or $_GET

 

;) ;) ;)

Link to comment
Share on other sites

Maybe you dreamed about it..

 

Last night after your posts, i took some small testing with hardcoded urls and guess what did i discovered:

 

<?php

/**
* Checks what global variable is set and display it
*/
if (isset($_POST['id'])) {
echo "POST: " . $_POST['id'];
}
elseif (isset($_GET['id'])) {
echo "GET: " . $_GET['id'];
}
else {
echo "Default!";
}

?>
<br />
<a href="tmp.php?id=product_id">Product Id</a>

 

and the output was:

GET: product_id
Product Id

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.