Cabbage Posted April 1, 2008 Share Posted April 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/98914-mysql-driven-website/ Share on other sites More sharing options...
jkewlo Posted April 1, 2008 Share Posted April 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/98914-mysql-driven-website/#findComment-506108 Share on other sites More sharing options...
ohdang888 Posted April 1, 2008 Share Posted April 1, 2008 if the data is dynamic, put it in a db. $url = @$_POST['id']; i believe its $_GET['id'] but it might be both, idk Quote Link to comment https://forums.phpfreaks.com/topic/98914-mysql-driven-website/#findComment-506110 Share on other sites More sharing options...
jkewlo Posted April 1, 2008 Share Posted April 1, 2008 no get will get it if it is comeing from a submit button. if he is going to do it with links then he will need to use the @$_POST method Quote Link to comment https://forums.phpfreaks.com/topic/98914-mysql-driven-website/#findComment-506111 Share on other sites More sharing options...
coder_ Posted April 1, 2008 Share Posted April 1, 2008 $_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!!! Quote Link to comment https://forums.phpfreaks.com/topic/98914-mysql-driven-website/#findComment-506112 Share on other sites More sharing options...
jkewlo Posted April 1, 2008 Share Posted April 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/98914-mysql-driven-website/#findComment-506114 Share on other sites More sharing options...
coder_ Posted April 1, 2008 Share Posted April 1, 2008 Now, i am reading your posts and it crushes everything i know about PHP. I am working in PHP for 3 yeary now, and never heard of url parsing by $_POST global variable. Quote Link to comment https://forums.phpfreaks.com/topic/98914-mysql-driven-website/#findComment-506117 Share on other sites More sharing options...
jkewlo Posted April 1, 2008 Share Posted April 1, 2008 do u want me to show u the code that i used? and it works Quote Link to comment https://forums.phpfreaks.com/topic/98914-mysql-driven-website/#findComment-506243 Share on other sites More sharing options...
ansarka Posted April 1, 2008 Share Posted April 1, 2008 ??? ??? ??? ??? $_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 ;) Quote Link to comment https://forums.phpfreaks.com/topic/98914-mysql-driven-website/#findComment-506246 Share on other sites More sharing options...
jkewlo Posted April 1, 2008 Share Posted April 1, 2008 then why did it work for me? master.php?id=General_Art $url = @$_POST['id'] code..... Quote Link to comment https://forums.phpfreaks.com/topic/98914-mysql-driven-website/#findComment-506248 Share on other sites More sharing options...
coder_ Posted April 1, 2008 Share Posted April 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/98914-mysql-driven-website/#findComment-506346 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.