PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dizeta
Forum Commoner
Posts: 47 Joined: Mon Feb 02, 2004 9:53 am
Post
by dizeta » Thu Apr 15, 2004 8:45 am
hello,
i'm a newbie
i have a problem with a query and/or a string to make an record downloadable
well, i've a DB with 2 tables:
table news
id_news auto_increment
title
date
author
news
table pdf:
id_pdf auto_increment
id_sharepdf
DatiBinari
Nome
Size
Type
Relationship 1 to 1
the script:
Code: Select all
<?php
include("dbconnect.php");
$getnews = mysql_query("select * from news ORDER BY id_news DESC")or die (mysql_error());
$query = mysql_query("SELECT pdf.Nome, pdf.id_pdf, news.id_news FROM pdf, news WHERE news.id_news = pdf.id_sharepdf ORDER BY id_news DESC")or die (mysql_error());
while ($row = mysql_fetch_array($getnews))
{
list ($nome)=mysql_fetch_row($query);
extract($row);
echo <<< NEWS
<div id="riga"><h3>Titolo: $title</h3></div>
<div id="riga1"=><h4>News inserita il $date - <b>Autore:</b> $author</h4></div>
<div id="riga2"><h5>$news</h5><img src="../../../immagini/pdf.gif" width="16" height="16" style="float: left;" /><h6>
<a href="download.php?action=download&Id={$nome['Nome']}" /><h6>{$nome}</h6></a>
<img src="../../../immagini/word.gif" width="16" height="16" style="float: left;" /><h6>$nome1</h6>
</div>
<div id="riga3"></div>
NEWS;
}
?>
now, the link :
Code: Select all
<?php
<a href="download.php?action=download&Id={$nome['Nome']}" /><h6>{$nome}</h6></a>
?>
doesn't work.
i need help to know where is the problem: link or query ( or both)?
thanks to all
AnsonM
Forum Commoner
Posts: 72 Joined: Thu Sep 25, 2003 7:21 am
Post
by AnsonM » Thu Apr 15, 2004 9:01 am
Im guessing its the link? It may not have been set properly?
dizeta
Forum Commoner
Posts: 47 Joined: Mon Feb 02, 2004 9:53 am
Post
by dizeta » Thu Apr 15, 2004 9:25 am
AnsonM wrote: Im guessing its the link? It may not have been set properly?
who knows? i'd like to know
normally must be
download.php?action=download&Id=id_pdf (example i've made 2 tests and into the table id_pdf= 60 and 61)
but i have :
download.php?action=download&Id=
2
and
download.php?action=download&Id=
c
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Apr 15, 2004 9:41 am
Try changing :
list ($nome)=mysql_fetch_row($query);
to
list ($nome)=mysql_fetch_assoc($query);
dizeta
Forum Commoner
Posts: 47 Joined: Mon Feb 02, 2004 9:53 am
Post
by dizeta » Thu Apr 15, 2004 9:48 am
markl999 wrote: Try changing :
list ($nome)=mysql_fetch_row($query);
to
list ($nome)=mysql_fetch_assoc($query);
this exclude from screen the name of the record {$nome}...
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Apr 15, 2004 9:50 am
Shouldn't you be using {$nome['Nome']} instead of {$nome} ?
dizeta
Forum Commoner
Posts: 47 Joined: Mon Feb 02, 2004 9:53 am
Post
by dizeta » Thu Apr 15, 2004 9:54 am
markl999 wrote: Shouldn't you be using {$nome['Nome']} instead of {$nome} ?
<a href="download.php?action=download&Id={$nome['Nome']}" /><h6>{$nome}</h6></a>
i'm refering to the last one: {$nome}
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Apr 15, 2004 10:01 am
Yeah, but $nome is now an array, so you need to use {$nome['whatever']} where whatever is the column from the db you want to show, eg something like:
<a href="download.php?action=download&Id={$nome['id_pdf']}" /><h6>{$nome['Nome']}</h6></a>
Also list ($nome)=mysql_fetch_assoc($query); should really just be:
$nome = mysql_fetch_assoc($query);
(sorry)
dizeta
Forum Commoner
Posts: 47 Joined: Mon Feb 02, 2004 9:53 am
Post
by dizeta » Thu Apr 15, 2004 10:16 am
markl999 wrote: Yeah, but $nome is now an array, so you need to use {$nome['whatever']} where whatever is the column from the db you want to show, eg something like:
<a href="download.php?action=download&Id={$nome['id_pdf']}" /><h6>{$nome['Nome']}</h6></a>
Also list ($nome)=mysql_fetch_assoc($query); should really just be:
$nome = mysql_fetch_assoc($query);
(sorry)
it works...!!
thanks...now i know how newbie i am...studying and learning...
bye