Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #7151

Re: Dynamic Links (MySQL/PHP)

Date 2012-09-25 20:02 +0200
From Luuk <luuk@invalid.lan>
Newsgroups comp.lang.php
Subject Re: Dynamic Links (MySQL/PHP)
References <ebad13b2-cbfd-412c-a199-4350f1168efb@googlegroups.com>
Message-ID <5689j9-i3i.ln1@luuk.invalid.lan> (permalink)

Show all headers | View raw


On 25-09-2012 19:27, tom.rankin51@googlemail.com wrote:
> Hello
>
> I have a very basic knowledge of PHP and MySQL and sought help from a friend who initially was someone I can turn to but now can't provide me with any help (!) ...and so to Google Groups!
>
> I am trying to display preview text on a webpage and then after clicking a link it will take you to the full item.  It must be quite a simple thing to do, however, I am getting a completely blank page.  I get no errors, and I have no syntax errors that I can see so I'm struggling to see what I have done wrongly.
>
> My code on the main page is :
>
> <?
>                      include("php/dbinfo.inc.php");
>
>                      mysql_connect($hostname,$username,$password);
>                      @mysql_select_db($database) or die( "Unable to select database");
>
> 					$mydate=date("Y-m-d",strtotime("-2 weeks"));
> 					
>    					$news_query=mysql_query("SELECT id, postdate, title, SUBSTRING_INDEX(body,' ',20) as preview_text, body FROM NewsContent WHERE postdate > '$mydate' ORDER BY postdate DESC");
> 					
>                      mysql_close();
>                      ?>
>
> <div>
>                     <ol>
>                     	<!-- START OF PHP SCRIPT (NEWS) -->
>                      <?
>                      while($r=mysql_fetch_assoc($news_query)) {
>                     		echo '<li id="'.$r["id"].'">';
>                     		echo '<h2 class="body-headline">';
> 						echo $r["title"];
>                     		echo '</h2>';
>                     		echo '<h3 class="date-heading">';
>                     		echo date("d-M-Y",strtotime($r["postdate"]));
>                     		echo '</h3>';
>                     		echo nl2br ($r["preview_text"]);
>                     		echo '...<a class="fancybox fancybox.ajax" href="news.php?id='.$r["id"].'">show more</a>';
>                      	echo '</li><hr />';
>                     	} ?>
>                     	<!-- END OF PHP SCRIPT (NEWS) -->
>                     </ol>
>                     </div>
>
> Note that I'm using a fancybox script, but this happens without using that script also.
>
> In my news item page I have done the following:
>
> <?
> 	include("php/dbinfo.inc.php");
> 	
> 	mysql_connect($hostname,$username,$password);
>      @mysql_select_db($database) or die( "Unable to select database");
> 					
> 	$id = $_GET['id'];
> 	$sql = "SELECT id, postdate, title, body FROM NewsContent WHERE id = '$id'";
> 	$news_query=mysql_query($sql);
> 	IF ($news_query){
> 		$r = mysql_fetch_row($news_query);
> 		
> 		$title = $r["title"];
> 		$body = $r["body"];
> 		}
> 	
> 	mysql_close();
> 	?>
>
> <div>
>              <h2>
>              	<?
>              	echo $r["title"];
>              	?>
>              </h2>
>              <div class="modal-nav-links">
>              <p><?php echo $r["body"] ?></p>
>              <!-- <div style="clear: both;"></div> -->
>              </div>
> </div>
>
>
> I was under the impression that this would work, but no dice.  Can someone with a bit of experience give me an idea of what I'm doing incorrectly?
>
> Thanks in advance
> Tom
>

There is a missing 'mysql_select_db()'
http://php.net/manual/en/function.mysql-select-db.php

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Dynamic Links (MySQL/PHP) tom.rankin51@googlemail.com - 2012-09-25 10:27 -0700
  Re: Dynamic Links (MySQL/PHP) The Natural Philosopher <tnp@invalid.invalid> - 2012-09-25 18:41 +0100
    Re: Dynamic Links (MySQL/PHP) tom.rankin51@googlemail.com - 2012-09-25 10:58 -0700
    Re: Dynamic Links (MySQL/PHP) tom.rankin51@googlemail.com - 2012-09-25 11:34 -0700
      Re: Dynamic Links (MySQL/PHP) Luuk <luuk@invalid.lan> - 2012-09-25 21:07 +0200
  Re: Dynamic Links (MySQL/PHP) Luuk <luuk@invalid.lan> - 2012-09-25 20:02 +0200
    Re: Dynamic Links (MySQL/PHP) tom.rankin51@googlemail.com - 2012-09-25 11:17 -0700
      Re: Dynamic Links (MySQL/PHP) Luuk <luuk@invalid.lan> - 2012-09-25 21:04 +0200
        Re: Dynamic Links (MySQL/PHP) tom.rankin51@googlemail.com - 2012-09-25 23:24 -0700
          Re: Dynamic Links (MySQL/PHP) Denis McMahon <denismfmcmahon@gmail.com> - 2012-09-26 14:03 +0000
  Re: Dynamic Links (MySQL/PHP) Captain Paralytic <paul_lautman@yahoo.com> - 2012-09-26 05:05 -0700
    Re: Dynamic Links (MySQL/PHP) Jerry Stuckle <jstucklex@attglobal.net> - 2012-09-26 11:16 -0400

csiph-web