danlew Posted May 1, 2007 Share Posted May 1, 2007 I want to be able to print from my database and output into php file, I need help with the code I have tried to create in php to read from this database, the whole code will work the same as worldpress.org. where it displays images and text , than they click on the title of the event and it takes them to a secondary page.... CREATE TABLE events ( id integer unsigned auto_increment primary key, title varchar(200) not null, `date` DATE not null, content longtext not null, image varchar(40) default null ) and this is the code of my php doc. <?php echo 'title-' . $link .'-'. strtolower($row['title]) .'.php'; ?>" width="60" height="50"></a></td> <td width="344" valign="top"><span class="style20"><span class="style22"><?php echo $row['biz_type']; ?></span><br> <?php echo 'image-' . $link .'-'. strtolower($row['image]) .'.php'; ?>"><img src="images/" width="60" height="50"></a></td> <td width="344" valign="top"><span class="style20"><span class="style22"><?php echo $row['biz_type']; ?></span><br> <?php echo substr($row['description'], 0 ,100); ?>.. <br> <span class="style21"><a href="<?php echo 'description-' . $link .'-'. strtolower($row['reference']) .'.php'; ?>"><u>Find out more.. </u></span></a></td> </tr> <?php } ?> I am sure this php doc needs to be fixed in order to display correctly from datasbe, please suggest some alter in code. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/49396-php-read-from-database-correctly/ Share on other sites More sharing options...
john010117 Posted May 1, 2007 Share Posted May 1, 2007 You haven't even connected to the database.... Quote Link to comment https://forums.phpfreaks.com/topic/49396-php-read-from-database-correctly/#findComment-242065 Share on other sites More sharing options...
danlew Posted May 1, 2007 Author Share Posted May 1, 2007 I have a seperate file to connect to database Quote Link to comment https://forums.phpfreaks.com/topic/49396-php-read-from-database-correctly/#findComment-242069 Share on other sites More sharing options...
john010117 Posted May 1, 2007 Share Posted May 1, 2007 Make sure you've put: include ("settings.php"); (replacing settings.php with the file to connect to the database) BEFORE any queries. Quote Link to comment https://forums.phpfreaks.com/topic/49396-php-read-from-database-correctly/#findComment-242076 Share on other sites More sharing options...
danlew Posted May 1, 2007 Author Share Posted May 1, 2007 Ok this is where im losing you, what code will settings.php need inside? Quote Link to comment https://forums.phpfreaks.com/topic/49396-php-read-from-database-correctly/#findComment-242082 Share on other sites More sharing options...
john010117 Posted May 1, 2007 Share Posted May 1, 2007 It will need your database settings, as well as the connect code. <?php // Connect to the database $host = "DB_HOST"; // db host $user = "DB_USERNAME"; // db username $pass = "DB_PASSWORD"; // db password $db = "DB_NAME"; // db name $connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect"); mysql_select_db ($db) or die ("Unable to select database"); ?> Make sure to replace the capitalized letters with your correct settings. Quote Link to comment https://forums.phpfreaks.com/topic/49396-php-read-from-database-correctly/#findComment-242083 Share on other sites More sharing options...
danlew Posted May 1, 2007 Author Share Posted May 1, 2007 I already have this code, I thought you were suggesting some other php file (settings.php) for the querie to read from. Anyone else here can help me to my above question please? Quote Link to comment https://forums.phpfreaks.com/topic/49396-php-read-from-database-correctly/#findComment-242097 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.