PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 22nd, 2013, 04:13 PM
w3l54666 w3l54666 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 52 w3l54666 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 14 h 19 m 25 sec
Reputation Power: 1
Question regarding php with mysql

hi,

how would i go about coding in another Database just for one section of the page.

Code:
<?php
// Variables
$dBIP='mysql4.000webhost.com'; 
$dBADN='a5344706_test'; 
$dBPWD='w3l54666';  
$dBDBS="a5344706_sigs";

// Connection
$CONNECT=mysql_connect($dBIP,$dBADN,$dBPWD);
$row=mysql_select_db($dBDBS, $CONNECT);
?>
<!DOCTYPE html>

<head>
	<meta charset="UTF-8">
	<title>News - Draig Racing</title>
	<link rel="stylesheet" href="css/style.css" type="text/css">
    
</head>
<body>
	<div class="page">
		<div class="header header-news">
        <a href="index.html" id="logo"><img src="images/logo.png" alt="logo"></a>
		  <ul>
			  <li>
					<a href="index.html">Home</a> <span></span>
				</li>
				<li>
					<a href="about.html">About</a> <span></span>
				</li>
				<li class="selected">
              		<a href="news.html">News</a> <span></span>
				</li>
                <li>
					<a href="http://www.draigracing.co.uk/phpBB3/index.php">Forum</a> <span></span>
				</li>
				<li>
					<a href="contact.html">Contact</a> <span></span>
				</li>
			</ul>
            <div class="featured">
			     
			 <h4>Featured News..</h4>
				<h3>Placeholder Title One</h3>
				<p>
				</p>
				<a href="about.html"></a>
			</div>
		</div>
		<div class="body">
			<div class="sidebar">
				<div>
					<h3>Connect</h3>
					<a href="https://twitter.com/DraigRacing/" id="twitter">twitter</a> <a href="https://www.facebook.com/DraigRacing" id="fb">fb</a> <a href="http://freewebsitetemplates.com/go/googleplus/" id="googleplus">google+</a>
				</div>
				<div>
					<div>
						<h3>Current F1 News links</h3>
						<ul>
							<li>
								<h4><a href="http://www.formula1.com/news/">Sky Sports F1</a></h4>
								<p>
									Current news on the formula 1 season, from all the teams.</p>
							</li>
							<li>
								<h4><a href="http://www.bbc.co.uk/sport/0/formula1/">BBC Sport F1</a></h4>
								<p>All news about formula 1 from the BBC's point of view.
								</p>
							</li>
							<li>
								<h4><a href="http://www.formula1.com/news/">Official Formula 1 Site</a></h4>
								<p>
									Offical outlet of all formula 1 news available here.
								</p>
							</li>
						</ul>
					</div>
				</div>
				<div>
					<div>
						<h3>Sim-racing Links</h3>
						<ul>
							<li>
								<h4><a href="http://www.rfactor.net">rFactor</a></h4>
								<p>
									Official rFactor site with news about rFactor 1 & 2.
								</p>
							</li>
							<li>
								<h4><a href="http://www.iracing.com">iRacing</a></h4>
								<p>
									Official iRacing website with news about different series available.
								</p>
							</li>
						</ul>
					</div>
				</div>
			</div>
			<div class="content">
			<ul>
				<?php

				// You only need a single query to draw all the news section
				// Remember that Limit number -currently 3- is just the news items you want to show in the main index

				$data = mysql_query("SELECT id, day, month, year, headline, text, signature, img1, img2, img3 FROM news ORDER by ID DESC LIMIT 3", $CONNECT);
				while($row = mysql_fetch_assoc($data))
				{

				echo '
						<li>
						<span>'.date('F ',$row['month']).' '.$row['day'].' ,'.$row['year'].'</span> <a href="#"><img src="images/racer2.jpg" alt=""></a>
						<div>
							<h3>'.$row['headline'].'</h3>
							<p>
								'.$row['text'].'
							</p>
							<a href="#">Read more >></a>
						</div>
					</li>';
				}
					
				?>
				
				</ul>
			</div>
		</div>
		<div class="footer">
			<ul>
				<li>
					<a href="index.html">Home</a>
				</li>
				<li>
					<a href="about.html">About</a>
				</li>
				<li>
					<a href="news.html">News</a>
				</li>
                <li>
					<a href="http://www.draigracing.co.uk/phpBB3/index.php">Forum</a>
				</li>
				<li>
					<a href="contact.html">Contact</a>
				</li>
			</ul>
			<p>
				© Copyright 2013. Draig Racing all rights reserved
			</p>
		</div>
	</div>
</body>
</html>


so i got this one database for collating news items, but i have a section just for featured news. i would like to use a databes to generate this obviously to cut down on always having to recode the page when needed.

is this possible and what code would i need?

many thanks

Reply With Quote
  #2  
Old February 22nd, 2013, 04:20 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 313 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
Are you aiming for a completely different database? Or perhaps just another table?

Reply With Quote
  #3  
Old February 22nd, 2013, 04:23 PM
w3l54666 w3l54666 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 52 w3l54666 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 14 h 19 m 25 sec
Reputation Power: 1
Quote:
Originally Posted by Triple_Nothing
Are you aiming for a completely different database? Or perhaps just another table?


what would u suggest?

if you want to know what im on about go to

http://draigracing.co.uk/Draigracingnewsite/news.html

its the featured news that i wanna do.

but like i said im really new to this so knowing best practice would be great

Reply With Quote
  #4  
Old February 22nd, 2013, 05:31 PM
E-Oreo's Avatar
E-Oreo E-Oreo is online now
Lost in code
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Dec 2004
Posts: 8,055 E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 1 Day 5 h 36 m 24 sec
Reputation Power: 7104
It is possible to use more than one database on a page, but you shouldn't do it unless you have to. If all you need is another table, then add it to your current database.
__________________
PHP FAQ
How to program a basic, secure login system using PHP
Connect with me on LinkedIn


Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #5  
Old February 23rd, 2013, 05:28 AM
w3l54666 w3l54666 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 52 w3l54666 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 14 h 19 m 25 sec
Reputation Power: 1
how come im getting this???

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a5344706/public_html/Draigracingnewsite/news.html on line 50

Reply With Quote
  #6  
Old February 23rd, 2013, 08:08 AM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 313 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
The variable you provide for it to fetch the associations from does not hold a valid MySQL result. Can you post those few lines making this call?

Reply With Quote
  #7  
Old February 23rd, 2013, 08:25 AM
w3l54666 w3l54666 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 52 w3l54666 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 14 h 19 m 25 sec
Reputation Power: 1
Quote:
Originally Posted by Triple_Nothing
The variable you provide for it to fetch the associations from does not hold a valid MySQL result. Can you post those few lines making this call?

Code:
<?php
// Variables
$dBIP='mysql4.000webhost.com'; 
$dBADN='a5344706_test'; 
$dBPWD='w3l54666';  
$dBDBS="a5344706_sigs";

// Connection
$CONNECT=mysql_connect($dBIP,$dBADN,$dBPWD);
$row=mysql_select_db($dBDBS, $CONNECT);
?>
<!DOCTYPE html>
<!-- Website template by freewebsitetemplates.com -->
<html>
<head>
	<meta charset="UTF-8">
	<title>News - Car Racing Website Template</title>
	<link rel="stylesheet" href="css/style.css" type="text/css">
    
</head>
<body>
	<div class="page">
		<div class="header header-news">
        <a href="index.html" id="logo"><img src="images/logo.png" alt="logo"></a>
		  <ul>
			  <li>
					<a href="index.html">Home</a> <span></span>
				</li>
				<li>
					<a href="about.html">About</a> <span></span>
				</li>
				<li class="selected">
              		<a href="news.html">News</a> <span></span>
				</li>
                <li>
					<a href="http://www.draigracing.co.uk/phpBB3/index.php">Forum</a> <span></span>
				</li>
				<li>
					<a href="contact.html">Contact</a> <span></span>
				</li>
			</ul>
            <div class="featured">
            <ul>
			     <?php

				// You only need a single query to draw all the news section
				// Remember that Limit number -currently 3- is just the news items you want to show in the main index

				$data1 = mysql_query("SELECT id, title, news, img1 FROM featured ORDER by ID DESC LIMIT 1", $CONNECT);
				while($row = mysql_fetch_assoc($data))
				{

				echo '
						<li>
						<span></span> <a href="#"><img src="images/racer2.jpg" alt=""></a>
						<div>
							<h3>'.$row['title'].'</h3>
							<p>
								'.$row['news'].'
							</p>
							<a href="#">Read more >></a>
						</div>
					</li>';
				}
					
				?>
                </ul>
			 <h4>Featured News..</h4>
				<h3>Placeholder Title One</h3>
				<p>
				</p>
				<a href="about.html"></a>
			</div>
		</div>
		<div class="body">
			<div class="sidebar">
				<div>
					<h3>Connect</h3>
					<a href="https://twitter.com/DraigRacing/" id="twitter">twitter</a> <a href="https://www.facebook.com/DraigRacing" id="fb">fb</a> <a href="http://freewebsitetemplates.com/go/googleplus/" id="googleplus">google+</a>
				</div>
				<div>
					<div>
						<h3>Current F1 News links</h3>
						<ul>
							<li>
								<h4><a href="http://www.formula1.com/news/">Sky Sports F1</a></h4>
								<p>
									Current news on the formula 1 season, from all the teams.</p>
							</li>
							<li>
								<h4><a href="http://www.bbc.co.uk/sport/0/formula1/">BBC Sport F1</a></h4>
								<p>All news about formula 1 from the BBC's point of view.
								</p>
							</li>
							<li>
								<h4><a href="http://www.formula1.com/news/">Official Formula 1 Site</a></h4>
								<p>
									Offical outlet of all formula 1 news available here.
								</p>
							</li>
						</ul>
					</div>
				</div>
				<div>
					<div>
						<h3>Sim-racing Links</h3>
						<ul>
							<li>
								<h4><a href="http://www.rfactor.net">rFactor</a></h4>
								<p>
									Official rFactor site with news about rFactor 1 & 2.
								</p>
							</li>
							<li>
								<h4><a href="http://www.iracing.com">iRacing</a></h4>
								<p>
									Official iRacing website with news about different series available.
								</p>
							</li>
						</ul>
					</div>
				</div>
			</div>
			<div class="content">
			<ul>
				<?php

				// You only need a single query to draw all the news section
				// Remember that Limit number -currently 3- is just the news items you want to show in the main index

				$data = mysql_query("SELECT id, day, month, year, headline, text, signature, img1, img2, img3 FROM news ORDER by ID DESC LIMIT 3", $CONNECT);
				while($row = mysql_fetch_assoc($data))
				{

				echo '
						<li>
						<span>'.date('F ',$row['month']).' '.$row['day'].' ,'.$row['year'].'</span> <a href="#"><img src="images/racer2.jpg" alt=""></a>
						<div>
							<h3>'.$row['headline'].'</h3>
							<p>
								'.$row['text'].'
							</p>
							<a href="#">Read more >></a>
						</div>
					</li>';
				}
					
				?>
				
				</ul>
			</div>
		</div>
		<div class="footer">
			<ul>
				<li>
					<a href="index.html">Home</a>
				</li>
				<li>
					<a href="about.html">About</a>
				</li>
				<li>
					<a href="news.html">News</a>
				</li>
                <li>
					<a href="http://www.draigracing.co.uk/phpBB3/index.php">Forum</a>
				</li>
				<li>
					<a href="contact.html">Contact</a>
				</li>
			</ul>
			<p>
				© Copyright 2013. Draig Racing all rights reserved
			</p>
		</div>
	</div>
</body>
</html>


this is my whole code,

the part thats playing up is this

Code:
 <div class="featured">
            <ul>
			     <?php

				// You only need a single query to draw all the news section
				// Remember that Limit number -currently 3- is just the news items you want to show in the main index

				$data1 = mysql_query("SELECT id, title, news, img1 FROM featured ORDER by ID DESC LIMIT 1", $CONNECT);
				while($row = mysql_fetch_assoc($data))
				{

				echo '
						<li>
						<span></span> <a href="#"><img src="images/racer2.jpg" alt=""></a>
						<div>
							<h3>'.$row['title'].'</h3>
							<p>
								'.$row['news'].'
							</p>
							<a href="#">Read more >></a>
						</div>
					</li>';
				}
					
				?>
                </ul>


thanks triple

Reply With Quote
  #8  
Old February 23rd, 2013, 08:29 AM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 313 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
I see 1 is called $data, while the other is $data1. Is this intended?

Reply With Quote
  #9  
Old February 23rd, 2013, 08:32 AM
w3l54666 w3l54666 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 52 w3l54666 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 14 h 19 m 25 sec
Reputation Power: 1
Quote:
Originally Posted by Triple_Nothing
I see 1 is called $data, while the other is $data1. Is this intended?


well i confess to know absolutely nothing about this, i thouhgt it was going to clash with the original $data.

the 1st one is my attempt at editing the 2nd one.

so maybe i got this wrong?

i did change the $data to $data1, but if its wrong then ill change it to what is needed

Reply With Quote
  #10  
Old February 23rd, 2013, 08:38 AM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 313 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
Well, as long as you're done with the prior $data info, you can always reset it. Make all 4 references just $data, and no $data1.

Reply With Quote
  #11  
Old February 23rd, 2013, 08:41 AM
w3l54666 w3l54666 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 52 w3l54666 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 14 h 19 m 25 sec
Reputation Power: 1
right they are all set as $data

still getting same error

Reply With Quote
  #12  
Old February 23rd, 2013, 08:45 AM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 313 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
If you're only getting an error from 1 of your mysql_fetch_assoc() then I would manually run your MySQL query and see if you get a valid response.


EDIT: And just a side note, which many will tell you here, try to take a step away from the deprecated mysql functions, and take a look into mysqli or PDO and use Prepared Statements.

Last edited by Triple_Nothing : February 23rd, 2013 at 08:49 AM.

Reply With Quote
  #13  
Old February 23rd, 2013, 08:49 AM
w3l54666 w3l54666 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 52 w3l54666 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 14 h 19 m 25 sec
Reputation Power: 1
Quote:
Originally Posted by Triple_Nothing
If you're only getting an error from 1 of your mysql_fetch_assoc() then I would manually run your MySQL query and see if you get a valid response.


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

Reply With Quote
  #14  
Old February 23rd, 2013, 08:50 AM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 313 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
Are you familiar with and have access to PHPMyAdmin? If so, run the query in there.

SELECT id, title, news, img1 FROM featured ORDER by ID DESC LIMIT 1

Reply With Quote
  #15  
Old February 23rd, 2013, 08:50 AM
w3l54666 w3l54666 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 52 w3l54666 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 14 h 19 m 25 sec
Reputation Power: 1
the lower mysql_fetch_assoc() works no problem coming from news table

but the one i posted which is line 50 isnt working from the featured table

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Question regarding php with mysql

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap