Tandem Posted July 21, 2006 Share Posted July 21, 2006 Ok, i'm trying ot set up a news system on my site. The form that inputs the data into the database table works completely fine, it's just displaying the news atricles that gets me confused, and all the google searches i try come up with explanations that are in a different context and hard for me to understand how to change it for my needs.I want to display the news that is in the database on a page. How do i do this?I'm not sure what information i need to give for you to be able to help me better, so please somebody say and i'll post whatever is needed.Thanks,-Tandem Quote Link to comment https://forums.phpfreaks.com/topic/15284-reading-from-database/ Share on other sites More sharing options...
tomfmason Posted July 21, 2006 Share Posted July 21, 2006 Post your code for the file that process the input from the form. Also I will need to know the primary key in the database table or auto incremented number Quote Link to comment https://forums.phpfreaks.com/topic/15284-reading-from-database/#findComment-61784 Share on other sites More sharing options...
kungfu71186 Posted July 21, 2006 Share Posted July 21, 2006 you need to query the data. this is an example, it was to populate a select box but ill pull some parts out so maybe you can get an idea. [code]<?php$result = mysql_query($sql) or die("Error with query (".$sql."): ".mysql_error()); $show_Combo_Box = "" ."<SELECT name=\"".$cb_name."\" id=\"".$idname."\" class=\"".$css_class."\" ".$disable."> \n" ."<OPTION value=\"0\">Select</OPTION>\n"; WHILE ($row = mysql_fetch_array($result)) { $selection = ""; if($id){ if($row['indexi'] == $id){ $selection = " selected "; } } $show_Combo_Box .= "" ."<OPTION value=\"".$row['indexi']."\" ".$selection.">" .$row['indexi']." (".$row['code'].") " ."</OPTION> \n"; } // End WHILE $show_Combo_Box .= "" ."</SELECT>\n"; mysql_free_result($result); echo $show_Combo_Box;?>[/code]but basically pay attention to the part where it says mysql_query. $sql is the query that i made before. So it gets a database(s) then does an orderby etc... You can always put the query directly in there.Im still new to mysql and php so there may be a better, but this is the only way i know how. mysql_query("SELECT column FROM table ORDER BY table ASC") you know something like that.But before you do anything you need to "load" up your database. require_once("./combo_box.conf.php");i called on that which has this in it$db['host'] = "localhost"; //mysql host/server$db['user'] = "user"; // mysql username$db['pass'] = "pass"; //mysql password$db['name'] = "database"; //mysql database nameif (!mysql_connect($db['host'], $db['user'], $db['pass'])){ displayErrorPage("Cannot connect to ".$db['host']."!"); exit;}@mysql_select_db($db['name']) or die (mysql_error());Hope that helps you get started. That $row[indexi] is a column i have as well as the code. You can also use 0 or 1 to get the first column. Quote Link to comment https://forums.phpfreaks.com/topic/15284-reading-from-database/#findComment-61787 Share on other sites More sharing options...
Tandem Posted July 21, 2006 Author Share Posted July 21, 2006 Don't worry i've figured out mysql_fetch_array from a tutorial! :) Quote Link to comment https://forums.phpfreaks.com/topic/15284-reading-from-database/#findComment-61798 Share on other sites More sharing options...
kungfu71186 Posted July 21, 2006 Share Posted July 21, 2006 WHILE ($row = mysql_fetch_array($result)) then try using tihs to get your values. Quote Link to comment https://forums.phpfreaks.com/topic/15284-reading-from-database/#findComment-61800 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.