Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2

    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 &amp; 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 &#62;&#62;</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>
    				&#169; 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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    724
    Rep Power
    7
    Are you aiming for a completely different database? Or perhaps just another table?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2
    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
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    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

    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
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2
    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
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    724
    Rep Power
    7
    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?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2
    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 &#62;&#62;</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 &amp; 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 &#62;&#62;</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>
    				&#169; 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 &#62;&#62;</a>
    						</div>
    					</li>';
    				}
    					
    				?>
                    </ul>
    thanks triple
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    724
    Rep Power
    7
    I see 1 is called $data, while the other is $data1. Is this intended?
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2
    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
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    724
    Rep Power
    7
    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.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2
    right they are all set as $data

    still getting same error
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    724
    Rep Power
    7
    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 09:49 AM.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2
    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.
    ?????????????
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    724
    Rep Power
    7
    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
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2
    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
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo