hi
i'm new in php, and i'm making my first db driven site.
it's something similar to "news" cms concept.
i made pages for uploading images, and inserting data into db table.
it works.
now i'm making a page where i want to display that content.
here, i need some hints.
i want to display only titles stored in one row of table, and make them to be a links to page that will show other content about that title.
can someone help me, or
is there some good tutorial where i can see how to do this?
thanks in advance

Recommended Answers

All 8 Replies

Member Avatar for diafol

Show us how your data is stored and which pages you have (not complete code, unless pertinent!)

ok, pages i already made:

- add.html (html forms)

- submit.php
connection to db and than:

if(isset($_POST['submit'])) {
$model=trim(htmlspecialchars(strip_tags(addslashes($_POST['model']))));
$opis=trim(htmlspecialchars(strip_tags(addslashes($_POST['opis']))));
$ime=trim(htmlspecialchars(strip_tags(addslashes($_POST['ime']))));
$telefon=trim(htmlspecialchars(strip_tags(addslashes($_POST['telefon']))));
$email=trim(htmlspecialchars(strip_tags(addslashes($_POST['email']))));
$file=$_FILES['file']['name'];

if ($model == "" || $opis == "" || $ime == "" || $email == "" || $file  == "" ){
echo "Niste uneli sve obavezne podatke. \n <a href='java script:history.go(-1)'>Vratite se na prethodnu stranu.</a>";
}
else {
$max_filesize = 262144;
 if(filesize($_FILES['file']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
else {
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
if ($file) 
{
$filename = stripslashes($_FILES['file']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))	
{
echo '<h1>Unknown extension!</h1>';
$errors=1;
}


else {
$uploads = dirname(__FILE__)."/slike_oglasi/";
$filename = rand(1000,99000).$_FILES['file']['name'];
copy($_FILES['file']['tmp_name'],$uploads.$filename) or die("Greška! Slika nije poslata. <a href='java script:history.go(-1)'>Nazad</a>");
$datum=date("d.m.Y");
$sql=mysql_query("INSERT INTO `proba` VALUES ('', '$model', '$opis', '$ime', '$telefon', '$email', '$filename','$datum')") or die(mysql_error()); 
echo "Vaš oglas je postavljen. Hvala";
}
}
}
}
}
?>

and inserted data is sent in db that contains 8 raws:
id, model, opis, ime, telefon, email, filename and datum

this 2 pages are ok, data is properly inserted in table.

now, index.php
i didn't create this code still, but i think i can handle it. this page will show list of values from "model" row, but what i don't know is- is it possible to make that values (models) to be links to the page called models.php? this page would show other values for wanted model. also, how to send information to models.php what particular model to show.

Member Avatar for diafol

OK, before I give you more hints, what type of models are you talking about here? Cars, women? I'm not comfortable with something about the latter.

:)
bass
i'm just getting in php, it's practice and there is no real meaning, it's not for particular website. just learning and testing my ability.

Member Avatar for diafol

You can retrieve data from the DB to produce a series of links.

Here's some pseudocode
$r = result of select query
loop through the resultset
extract the modelname and id values
build the links: <a href="model.php?id=<?php echo $data;?>"><?php echo $data;?></a>

Your model.php page can display dynamic data based on the 'id':

$id = $_GET;
run a query to extract the data based on that id value, e.g.

"SELECT * FROM table WHERE id = $id"

yea, it works, thank you very much!

Member Avatar for diafol

Ok, great. Are we solved?

sure,
when code works, i feel like wizard, and i'm happy like a child.
thnx again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.