Jump to content

[SOLVED] Urgently need help!! PHP Link


ow-design

Recommended Posts

  • Replies 69
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Can I just confirm this...

 

You want to pull a list of, let's say, job titles from a database with perhaps a little information about each one. Not all the information, just a small taster. There will be a "more" link so the user can click a particular job which will take them to another page that will then show the user everything about that job?

Link to comment
Share on other sites

Here's some code I've written for a project I'm working on now. It shows you how to do it although you'll have to edit it. If you want me to simplify it let me know.

<?php
  $eventctr=0;
  $pagehtml.='<table width="100%" cellspacing="1" cellpadding="0" class="lbluout">'."\n";
  $pagehtml.='  <tr class="lbluin"><td class="lbluhdr"><img src="gfx/hdr_'.$pageinfo[1].'.gif" alt="'.$pageinfo[2].'" width="150" height="16" border="0" /></td></tr>'."\n";
  $query=mysql_query("SELECT title,type,body,dt,userid FROM articles WHERE `status`='Active' ORDER BY `dt` DESC");
  while ($fetch=mysql_fetch_assoc($query)) {
    $fetchtype=mysql_fetch_assoc(mysql_query("SELECT type FROM article_types WHERE `typeid`='".$fetch['type']."'"));
    $fetchname=mysql_fetch_assoc(mysql_query("SELECT username FROM phpbb_users WHERE `user_id`='".$fetch['userid']."'"));
    $pagehtml.='  <tr class="lbluin"><td class="lblutext"><a href="readarticle.php?id='.$fetch['articleid'].'" class="urlt">'.$fetch['title'].'</a> ('.$fetchtype['type'].', posted '.date("d-M-Y \a\\t H:i",$fetch['dt']).' by <a href="viewprofile.php?id='.$fetch['userid'].'" class="url">'.$fetchname['username'].'</a>)<br /><br />'.substr($fetch['body'],0,170).'...</td></tr>'."\n";
    $eventctr++;
  }
  $pagehtml.='</table><br />'."\n";
?>

Above is pulling a list of articles from the database and showing a taster with the title of the article (could be your job title?) being the "more" link. Shouldn't be too hard to adapt.

 

As I've not yet written the routine to display the article I'll write a sample script while you look at the above...

Link to comment
Share on other sites

thats great, it has a lot of stuff idont need really.

there are no users.

 

would anybody be willing to give me the exact full code script i need.

 

I need a jobs.php page where there is a table with 2 columns [id] & [name] with a link (automatically generated) that points to jobdetails.php where the same table is displyed with [id] & [title] and below that the decription [description]

 

thats basically it really.

it porbably sound really easy to do for all the experts out their, i am brand new to php and really need all the help and genrosity i can get!

 

I really aprrecaite all your help & comments! :)

Ollie

Link to comment
Share on other sites

This is for getting the article/job and viewing it (not tested as this is straight off the top of my head):

<?php
  $jobid=$_GET['id'];
  if (is_numeric($jobid)) {
    $sql="SELECT * FROM jobs WHERE `jobid`='$jobid'";
    $fetch=mysql_fetch_assoc(mysql_query($sql));
    echo '<strong>Job title:</strong> '.$fetch['title'].'<br /><br />';
    echo '<strong>Details:</strong> '.$fetch['details'].'<br /><br />';
    echo '<strong>Wages:</strong> '."£".$fetch['wages'].$fetch['rate'];
  }

This would output something like this:

Job title: I.Tee Boy

Details: Make lots of tea for the real coders, being on call to make tea at any time. Must be experienced at making tea with and without a spoon blah blah blah.

Wages: £1.76ph

thats great, it has a lot of stuff idont need really.

there are no users.

As I said, I can simplify it if you want...

Link to comment
Share on other sites

Asking someone to write you the exact code for you to use is sort of defeating the object of this site (jesirose or someone correct me if I'm wrong) but is instead here to help you to write things yourself and therefore learn something.

 

As it happens I've got some spare time before I have to go to bed as I'm recording a programme from the TV for my fiance so I'll offer what help I can before I have to leave.

 

EDIT: Mis-spelt "spare" :-[

Link to comment
Share on other sites

I agree totally with Yesideez on this.

 

I am fairly new to PHP (about 4 months, i'm 19) and I just read a lot of articles and buy reference books or a very good way to learn any programming language is by video tutorials.

 

Just remember that if you always ask people to do it, 1) You will not learn anything 2) Thats the way you will always do it, by piecing together other people's scripts and just managing to make what you need

 

Check out http://www.phpvideotutorials.com/

 

Very good stuff there.

 

Link to comment
Share on other sites

Here is a simplified version:

  <table width="600" border="1">
<?php
  $sql="SELECT * FROM jobs ORDER BY `jobid` DESC";
  $query=mysql_query($sql);
  while ($fetch=mysql_fetch_assoc($query)) {
    echo '    <tr><td>Title: '.$fetch['title'].'</td><td align="right"><a href="jobdetails.php?id='.$fetch['jobid'].'">[more]</a></td></tr>';
    echo '    <tr><td colspan="2">Details: '.$fetch['details'].'</td></tr>';
  }
?>
  </table>

Off the top of my head so I can't guarantee it'll work - you'll need to change the MySQL details for what you call the table and field names.

 

EDIT: Forgot the </a> to terminate the link :-[

Link to comment
Share on other sites

In a nutshell, you need to define your MySQL call to the database.

 

Using a loop (I'm using a while() loop) run through the results one by one and send them to the browser formatted using a table (if you want to use one). Once the while() loop has finished, close the table and carry on with the rest of the page.

<?php
 <a href="jobdetails.php?id='.$fetch['jobid'].'">[more]</a>
?>

Basically you make a link as normal and "insert" the id number where you want it. If you use single quotes instead of double ones you don't have to prefix some characters with a slash although you can't access variables like you can in double quotes.

Link to comment
Share on other sites

well i doubt my client will ask as he wont be looking at the code just the final design, he does nt really know much about computers anyway.

 

i know it might seem like i am trying to chrat my way thorugh this but i have been trying so hard to get this working but i just can't

 

As for that code you just posted, how do i implement that. do i just start with a blank php doc and post that script with my database connect details??

 

I  am really struggling here?? Really sorry to be annoying you pro's!

Link to comment
Share on other sites

okay below is the oce for jobs.php as it currently looks now.

 

<?php

include("db.php");

// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$result = mysql_query("select * from jobs order by id asc");
?>
	<html>
	<head>
	<title> Product List </title>
	</head>
	<body bgcolor="#ffffff">

<h1>Current Jobs</h1>

<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr> 
    <td width="9%" height="25" bgcolor="red"> <strong><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="white"> 
       Ref#</font> </strong></td>
    <td width="80%" height="25" bgcolor="red"> <strong><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="white"> 
      Job Title</font> </strong></td>
    <td width="11%" height="25" bgcolor="red"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font> 
    </td>
  </tr>
  <?php
		while($row = mysql_fetch_array($result))
		{
		?>
  <tr> 
    <td width="9%" height="25"> <strong><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="black"> 
      <?php echo $row["id"]; ?> </font> </strong></td>
    <td height="25"> <strong><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="black"> 
      <?php echo $row["name"]; ?> </font> </strong></td>
    <td width="11%" height="25"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<a href="jobdetails.php?<?php echo $row["id"]?>">More About Vacancy</a></font></td>
  </tr>
  <tr> 
    <td colspan="3"> <hr size="1" color="red" NOSHADE> </td>
  </tr>
  <?php
		}
	?>
  <tr> 
    <td colspan="3"> </td>
  </tr>
</table>
</body>
</html>

 

and here is my jobdetails.php code as it looks now

<?php


include("db.php");

// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);


<table width="600" border="0">;
<?php
  $sql="SELECT * FROM jobs ORDER BY `jobid` DESC";
  $query=mysql_query($sql);
  while ($fetch=mysql_fetch_assoc($query)) {
    echo '    <tr><td>Title: '.$fetch['title'].'</td><td align="right"><a href="jobdetails.php?id='.$fetch['jobid'].'">[more]</a></td></tr>';
    echo '    <tr><td colspan="2">Details: '.$fetch['details'].'</td></tr>';
  }
?>
  </table>
  </html>

 

I really need all your help in getting this working, i realise that currently this is all wrong but all the scripts everyone has been posting aren't working correctly.

Please sdjust code above to my specifications as pointed out in previous posts.

 

Much appreciated!.

Ollie

Link to comment
Share on other sites

Here's the first script:

<?php

include("db.php");

// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
?>
	<html>
	<head>
	<title> Product List </title>
	</head>
	<body bgcolor="#ffffff">

<h1>Current Jobs</h1>

<table width="100%" cellspacing="0" cellpadding="0" border="0">
<?php
  $sql="SELECT * FROM jobs ORDER BY `id` DESC";
  $query=mysql_query($sql);
<?php while ($fetch=mysql_fetch_assoc($query)) { ?>
  <tr> 
    <td width="9%" height="25"> <strong><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="black"> 
      <?php echo $fetch["id"]; ?> </font> </strong></td>
    <td height="25"> <strong><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="black"> 
      <?php echo $fetch["name"]; ?> </font> </strong></td>
    <td width="11%" height="25"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<a href="jobdetails.php?<?php echo $fetch["id"]?>">More About Vacancy</a></font></td>
  </tr>
  <tr> 
    <td colspan="3"> <hr size="1" color="red" NOSHADE> </td>
  </tr>
<?php } ?>
  <tr> 
    <td colspan="3"> </td>
  </tr>
</table>
</body>
</html>

Now have a go with that and see how you go.

Link to comment
Share on other sites

great thankyou!, i am getting the following error.

 



Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/deswo/public_html/clients/martin_pooley/jobs.php on line 21


 

line 21 =

 

 

while ($fetch=mysql_fetch_assoc($query)) { ?>

 

 

Any ideas?

Link to comment
Share on other sites

fixed! okay fixed that error so jobs.php is now working.

 

with the code you just gave me for jobs.php will that link to jobdetails.php is the code in jobs.php already?

 

Sorry i really cannot get to grips with how php works yet.

 

Really appreciate what you are doing!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.