Forum Moderators: coopster

Message Too Old, No Replies

newbie question

php-mysql

         

normsky

5:13 pm on Jan 30, 2003 (gmt 0)

10+ Year Member



hi,
I made the following tables in a database:

create table gallerie(
id int not null primary key auto_increment,
galname varchar(100),
url varchar(255)
);

i also made a html file to upload the info and it works.

Now i want to show(view/place) the info placed in galname on my site which is linked to the info placed in url.

so if i placed gallerie1 in my database under galname and
www.mygallerie.com/gal.html under url.
I want to place gallerie1 on my site which is linked to www.mygallerie.com/gal.html

I tried a few different ways but can't get it to work
I'm realy realy new at this.
can some one help me.

Thanks,
Norm

[edited by: jatar_k at 10:19 pm (utc) on Jan. 30, 2003]
[edit reason] delinked [/edit]

Quinn

9:56 pm on Jan 30, 2003 (gmt 0)

10+ Year Member



Not sure if I follow you. First things first....
Do you have your PHP page connected to the database yet?

normsky

10:36 pm on Jan 30, 2003 (gmt 0)

10+ Year Member




This is what i want to do:

Database galleries;
Table gallerie in database galleries:

ID Gallerie name url
1 gallerie 01 [mysite...]
2 gallerie 02 [mysite...]
3 gallerie 03 [mysite...]

Now i want to show on my site:
gallerie 01
gallerie 02
gallerie 03

which are linked to the url given in the database.

So i want to put the info in a database and show it with php code.

Thanks,
Norm

jatar_k

10:49 pm on Jan 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



$sq = "select * from gallerie";
$squery = mysql_query($sq);
while ($sqrow = mysql_fetch_array($squery)) {
echo "<a href=\"", $sqrow['url'], "\">", $sqrow['galname'], "</a><br>\n";
}

very quick but that should work, should give you something like this

<p><a href="www.mysite/gal01.html">gallerie 01</a><br>
<a href="www.mysite/gal02.html">gallerie 02</a><br>
<a href="www.mysite/gal03.html">gallerie 03</a><br>

RussellC

10:50 pm on Jan 30, 2003 (gmt 0)

10+ Year Member



if the info is already in the DB and you have php connected to the DB. Then you could just do something like.

<?php
$sql = "SELECT * FROM gallerie";
$query = @mysql_query($sql);
while ($row = @mysql_fetch_array($query)) {
$ID = $row["ID"];
$galname = $row["galname"];
$url = $row["url"];
?>
<table>
<tr>
<td><?=$ID?>td>
<td><?=$galname?></td>
<td><a href="<?=$url?>"><?=$url?></a></td>
</tr>
</table>
<?php
}
?>

[edited by: RussellC at 10:51 pm (utc) on Jan. 30, 2003]

RussellC

10:50 pm on Jan 30, 2003 (gmt 0)

10+ Year Member



Dang you are too quick jatar

jatar_k

10:54 pm on Jan 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



;)

you were much more elaborate, I figured normsky could figure out the formatting, I didn't want to do all of the homework assignment. I wanted it to have to be customized and therefore better understood.

by the way,
Welcome to WebmasterWorld normsky

normsky

10:56 pm on Jan 30, 2003 (gmt 0)

10+ Year Member



Ok,
Thanks i'm going to work on it.
I realy appreciate your help.

Thanks,
Norm

normsky

11:30 pm on Jan 30, 2003 (gmt 0)

10+ Year Member



Hope you guys are still here,

I bought a book the learn but as always i want to go to fast and just use what i need and noticed it does not work.

The examples in the book are not what i need and when i try to change it to what i want it does not work.

I 'am trying to insert the data like this:

$sql="insert into gallerie set
galname='$galname',
url='$url'";
if( @mysql_query($sql)) {
echo("<p>Your gallerie has been added.</p>");
}else{
echo("<p>Error adding submitted gallerie: " .
mysql_error() . "</p>");
}

It tels me that the gallerie has been added but when i look in the database(mysql) all it added was an ID the galname and url stay blank (If i enter the data directly in mysql its fine)
There might be something wrong with my code.

jatar_k

11:37 pm on Jan 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try this as your insert query

$sql="insert into gallerie values ('','" . $galname . "','" . $url . "')";

You can look here too
[mysql.com...]

<added>when testing I wouldn't use the @ symbol before your function calls, it suppresses errors. I use this to get the mysql error

mysql_query($sql) or die ("<BR>" . mysql_error() . "<BR>");

normsky

1:33 am on Jan 31, 2003 (gmt 0)

10+ Year Member



hi,
I tried this:
$sql="insert into gallerie values ('','" . $galname . "','" . $url . "')";

And a few other ways and it gives the message that the gallerie was added to the database but when i look in the database all thats added is the ID.

The field for galname and url stay blank
no mather what i tried it looks like it does not insert the data into the database.

Help

Thanks,
Norm

Birdman

1:50 am on Jan 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The way I troubleshoot my MySql queries is:
  1. echo your $sql variable on the destination page
  2. go to phpMyAdmin and paste the statement into the execute sql box
  3. adjust your query until you get proper results
  4. paste working sql to script

Just my way ;)

jatar_k

8:48 pm on Jan 31, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that's a very good way Birdman

I had to edit my last post about 100 times because I kept making mistakes so let me break it down better.

$url = "www.mysite/gal01.html";
$galname = "gallerie 01";

query should look like this

insert into gallerie values ('','gallerie 01','www.mysite/gal01.html')

so we need to create this by using the variables. I rechecked that query and it is fine.

It looks like your vars don't have any values. You said you were using a form to insert the rows, I have a sneaking suspicion that the values aren't being passed properly or you are not accessing these values properly to attribute them to the vars.

if you are using a form you should have textboxes like so
<input type="text" name="galname">
<input type="text" name="url">

this will then use the post method to send to the script that does the inserting.

In that script you can access these vars by doing
$galname = $_POST['galname'];
$url = $_POST['url'];
then carrying on with your insert. You could test if the vars are receiving values by skipping the insert for now and doing something like this where your insert is now.

echo "<p>url: " . $url;
echo "<p>galname: " . $galname;
echo "<p>query: " . $sql;

this will show you all of the variables and you can better assess where the problem is.

normsky

3:54 pm on Feb 2, 2003 (gmt 0)

10+ Year Member



Hi,
Thanks again for all your help
This is harder then i tought.

While i'm "fighting" with this i learn more by the minute.

I think it is possible to get the same result with out using a database.

I made the following:

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Title here!</title>
<style type="text/css">
font-family:Normal,Helvetica;}
A:active{COLOR:#FF0000;FONT-FAMILY:normal;FONT-SIZE:12px;TEXT-DECORATION:none}
A:link{COLOR:#000000;FONT-FAMILY:normal;FONT-SIZE:12px;TEXT-DECORATION:none}
A:visited{COLOR:#000000;FONT-FAMILY:normal;FONT-SIZE:12px;TEXT-DECORATION:none}
a:hover{COLOR:#000080;FONT-FAMILY:normal;FONT-SIZE:12px;TEXT-DECORATION:underline}
</style>
</head>
<body>
<?php
$var2="http://wwww.mysite.com";
?>
<?php
$count= 1;
while ($count <= 10) {
echo'<a href="$var2">Gallerie</a><br />';
$count++;
}

?>
</body>
</html>

It outputs this:

Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]

I would like it to output This:

Gallerie 01 [mysite.com]
Gallerie 02 [mysite.com]
Gallerie 03 [mysite.com]
Gallerie 04 [mysite.com]
Gallerie 05 [mysite.com]
Gallerie 06 [mysite.com]
Gallerie 07 [mysite.com]
Gallerie 08 [mysite.com]
Gallerie 09 [mysite.com]
Gallerie 10 [mysite.com]

I tried and tried and are still trying.

Thanks,
Norm

andreasfriedrich

4:05 pm on Feb 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure whether you asked a question. But here is a suggestion how to achieve what you seem to want.

printf [php.net]('<a href="%s/gallery_%02d">Gallerie %02d</a>', $var2, $i);

BTW I hope that the word Gallerie is not meant to be German since then it would need to be Galerie: Es kommt halt nicht von Galle ;).

Andreas

Birdman

4:18 pm on Feb 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$sql = "SELECT id, galname FROM galleries";
$result = mysql_query($sql);

while ($i = mysql_fetch_array($result)){
echo "<a href='gallerie.php?id=$i[id]'>Gallerie $i[galname]</a><br />";
}

This should output the following HTML:

<a href='gallerie.php?id=1'>Gallerie 1</a><br />
<a href='gallerie.php?id=2'>Gallerie 2</a><br />
<a href='gallerie.php?id=3'>Gallerie 3</a><br />
etc...

Notice all links point to the same page but have a query string(?id=) at the end of the link. Now you create gallerie.php and put a SQL statement on that page that searches another table that holds the content for each gallerie.

You need to create a table for your gallerie items and make sure you have a gallerie_id field. This is how you control which items appear in each gallerie.

Am I making any sense to you? It can be a bit confusing at first, but it is a nice way to manage your site.