hawkontvn Posted November 6, 2009 Share Posted November 6, 2009 Hey! I'm quite new to this whole thing, so please don't fire me with shait on this one =D I'm trying to learn PHP and MySQL, and atm I am trying to make a website which corresponds with a database - a database with customers. I managed to make the page show all the customers in the database - with first- and surname. I want each of these customers to be clickable - when you click a customer, it shows all the information about that customer which is stored in the database. So far I have managed to make them clickable, but I don't know how to make it so that the click posts all the associated information about that customer on the page.. I can post some of the stuff I tried out with, but I'm not good with PHP (yet! =D), and therefore I got stuck quite early... but here's some of the stuff I've done so far.. <?php // Connect to the database server $dbcnx = @mysql_connect('localhost', 'root', 'password'); if (!$dbcnx) { exit('<p>Unable to connect to the database server at this time.</p>'); } // Select the database if (!@mysql_select_db('customerdb')) { exit('<p>Unable to locate the database at this time'); } ?> <p>Here are all the customers:</p><br /> // Request data from the database $customers = @mysql_query('SELECT * FROM customers'); if (!$customers) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while ($row = mysql_fetch_array($customers)) { $customerID = $row['kundeID']; $customer_forename = $row['forename']; $customer_surname = $row['surname']; echo '<p>' . $customer_forename . $customer_surname . ' <a href="' . $_SERVER['PHP_SELF'] . '?showcustomer=' . $customerID . '">' . 'customer details</a></p>'; } ?> Thanks! Quote Link to comment Share on other sites More sharing options...
JJ2K Posted November 6, 2009 Share Posted November 6, 2009 Yea that's the right track, so when somebody clicks on the customer details for a customer they are taken to the URL myfile.php?showcustomer=15 Where 15 is the customer ID. Then on my file.php you just get this value and look for it in the database like: <?php if($_GET['showcustomer']){ //Then Somebody is on a Customer Details Page //Get the Customer ID Value from the URL $custID = $_GET['showcustomer']; echo "Hello, Here are Customer Details for the customer with ID: $custID <br />"; //Search For Customer Information Based on the ID Given $query= "SELECT FROM tablename WHERE custID = $custID"; $res = mysql_query($query) or die(mysql_error()); //Now Loop Through the Result and Display The Information found about the ID while(mysql_fetch_array($res) = row){ //echo out customer details here } } ?> You'd replace tablename with table name and custID with the field name that stores the customer ID field. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted November 6, 2009 Share Posted November 6, 2009 JJ2K nailed it on the head...just link to another script dedicated to showing your data, and send it the user id, retrieve the relevant info from the db and display it Quote Link to comment Share on other sites More sharing options...
hawkontvn Posted November 6, 2009 Author Share Posted November 6, 2009 Thanks for the help I managed it all pretty well, though I think my code got a lil' bit more messy than it could have been... anyways, I have one last problem.. I tried echoing the customer details out into a table.. i managed the table itself, but somehow it fucked up the css or at least look of the page.. my page is a 3-column-awebsite.. It is divided into three <div>'s, like this: <div id="left"> - left column </div> <div id="right"> - right column <div id="right2"> - a col inside the right one, making up the middle col. </div> (end of right2 div) </div> (end of right div) So, when I echoed out the table with my data into the right column (div id="right"), it somehow overlapped into the right2 div, and fucked up the whole page any ideas? thanks! Quote Link to comment Share on other sites More sharing options...
JJ2K Posted November 6, 2009 Share Posted November 6, 2009 Yep defo a HTML/CSS problem, just mess around with the table widths Quote Link to comment Share on other sites More sharing options...
hawkontvn Posted November 6, 2009 Author Share Posted November 6, 2009 Thought so, but I can't seem to figure it out. If I use css to rezise it, I don't just rezise my table, I resize the whole div col that the table overlaps into (div id="right")... :/ Quote Link to comment Share on other sites More sharing options...
JJ2K Posted November 6, 2009 Share Posted November 6, 2009 Can't you just do something like this: <table width="50" Start off with a small value and then get bigger just to see if it solves the col drop, if not post a link and i'll take a quick look. Quote Link to comment Share on other sites More sharing options...
hawkontvn Posted November 7, 2009 Author Share Posted November 7, 2009 Nah, that won't help it - already tried it out..think its because the minimum size of the table (because of the content) is too big - even though its not such a big table.. the funny thing is i tried to make the columns bigger so that the table would fit, but still no luck.. Quote Link to comment 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.