Jump to content

[SOLVED] generate url from mysql table data


NoDoze

Recommended Posts

You have to be a little more specific.  Something like this:

 

$sql = "SELECT * FROM table WHERE something = something";
$result = mysql_query($sql);
while($row = $mysql_fetch_array($result)) {
?>
http://domain.com/script.php?ID=&ID2=&ID3=

Link to comment
Share on other sites

To add to this...

 

I'm also trying to import a text file into mysql from  bash script:

#!/bin/bash
mysql -uroot -e "LOAD DATA INFILE '/home/user/prelim.txt'; INTO TABLE database.table; FIELDS TERMINATED BY ',';"

 

...but I keep getting:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

...when I run the script.

 

However, when I copy/paste this:

mysql -hlocalhost -uroot
LOAD DATA INFILE '/home/user/prelim.txt'
INTO TABLE database.table
FIELDS TERMINATED BY ',';
\q

...into the CLI via ssh it works perfectly!

 

Can someone help and tell me what I'm doing wrong?

 

Thanks!

Link to comment
Share on other sites

Curious about the first question I asked...

 

In this...

$sql = "SELECT * FROM table WHERE something = something";
$result = mysql_query($sql);
while($row = $mysql_fetch_array($result)) {
?>
http://domain.com/script.php?ID=<?php echo $row['Xvalue']; ?>&ID2=<?php echo $row['Yvalue']; ?>&ID3=<?php echo $row['Zvalue']; ?>
<?php } ?>

 

I'm trying to pull the most recent data row from the database to enter into the url, then send this url. Which is why I don't think I need the WHERE clause, but is it required? And how would I send the URL?

Link to comment
Share on other sites

ok so far I have this:

 

<?php


include 'config.php';
include 'opendb.php';

$query="SELECT * FROM table";
$result=mysql_query($query);


header('Location: http://domain.com/subfolder/update.php?ID=value1&PASSWORD=value2&dateutc='.$_POST['date'].'&data1='.$_POST['data_1'].'&data2='.$_POST['data_2'].'&data3='.$_POST['data_3'].'&data4='.$_POST['data_4'].'&weather=&clouds&action=updateraw');


include 'closedb.php';

?> 

 

But it doesn't post the data from the table... Should it be POST, or GET? ...or something else.

I'm really confused on what the difference is between POST and GET...

 

thanks.

Link to comment
Share on other sites

Ok, I'm SO close... But still no cigar... This is what I have so far:

 

<?php


include 'config.php';
include 'opendb.php';


$sql = "SELECT * FROM hicks ORDER BY date ASC LIMIT 1";

header('Location: http://domain.com/update.php?ID=username&PASSWORD=password&dateutc='.$_GET['date'].'&tempf='.$_GET['airt_f_avg'].'&winddir='.$_GET['winddir'].'&windspeedmph='.$_GET['ws_mph'].'&windgustmph='.$_GET['0'].'&rainin='.$_GET['rain_in_tot'].'&baromin='.$_GET['0'].'&dewptf='.$_GET['dewpt_f_avg'].'&humidity='.$_GET['rh_avg'].'&weather=&clouds=&action=updateraw')


include 'closedb.php';

?> 

 

But when executed, the page comes up blank. And when I remove the database open/config/close info, I get a URL, but with no data...

 

 

And this...

<?php


include 'config.php';
include 'opendb.php';


$result = mysql_query("SELECT * FROM hicks ORDER BY date ASC LIMIT 1");

while($row = mysql_fetch_array($result))
  {
  echo $row['date'] . " " . $row['time'] . " " . $row['record'] . " " . $row['pt_ft'] . " " . $row['pipeq_gal_tot'] . " " . $row['rain_in_tot'] . " " . $row['ws_mph'] . " " . $row['winddir'] . " " . $row['slrw_avg'] . " " . $row['airt_f_avg'] . " " . $row['tw_f_avg'] . " " . $row['dewpt_f_avg'] . " " . $row['rh_avg'] . " " . $row['e_kpa_avg'] . " " . $row['eto_mm'] . " " . $row['solarradcalc'];
  }


include 'closedb.php';

?> 

 

Gets the data but not in URL form.

 

I need to somehow combine the two!

 

HELP!

 

Thanks.

Link to comment
Share on other sites

If you want to produce a link for each row you need to:

 

1) Use a while loop so it can extract ALL the rows from the DB.

2) Change post to $row (or whatever variable you want to use).  $_POST is for transferring data from page to page.

3) The header redirects people automatically.  I imagine you want to have people click on a desired link, so just display the links as hrefs.

 

Try this *not tested*:

 

include 'config.php';
include 'opendb.php';

$query="SELECT * FROM table";
$result=mysql_query($query);
$i = 0;
while($row = mysql_fetch_array($result)) {
$i++;
?>

Link 


include 'closedb.php';

?>

Link to comment
Share on other sites

You can combine HTML and PHP in two ways:

1) echo out your HTML.
2) close PHP and open it back up when you need it.

(I prefer the 2 because I hate dealing with single and double quotes, gets confusing sometimes.)

But here's #1:

$sql = "SELECT * FROM hicks ORDER BY date ASC LIMIT 1";
$row = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
echo "your link!"; 

Link to comment
Share on other sites

yes uploading data via HTTP GET...it's what they require...

 

I tried:

<?php

include 'config.php';
include 'opendb.php';

$sql = "SELECT * FROM hicks ORDER BY date ASC LIMIT 1";
$row = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
echo "<a href='http://domain.com/update.php?ID=username&PASSWORD=password&dateutc=" . $row['date'] . "&tempf=" . $row['airt_f_avg'] . ">your link!</a>"; 

include 'closedb.php';

?>

After clicking the link, still creates a URL with no data.

Link to comment
Share on other sites

<?php

include 'config.php';
include 'opendb.php';

$sql = "SELECT * FROM hicks ORDER BY date DESC LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);

header("http://domain.com/update.php?ID=username&PASSWORD=password&dateutc=" . $row['date'] . "&tempf=" . $row['airt_f_avg'] . "&winddir=" . $row['winddir'] . "&windspeedmph=" . $row['ws_mph'] . "&windgustmph=" . $row[''] . "&rainin=" . $row['rain_in_tot'] . "&baromin=" . $row[''] . "&dewptf=" . $row['dewpt_f_avg'] . "&humidity=" . $row['rh_avg'] . "&action=updateraw");

include 'closedb.php';

?>

 

This is the only way I can think it would work. But it doesn't. Can someone enlighten me, thanks.

 

Newbie

Link to comment
Share on other sites

ok, I think I figured it out... I tested this and it worked!!!! SWEETNESS!!! LOL

 

<?php

include 'config.php';
include 'opendb.php';

$sql = "SELECT * FROM hicks ORDER BY date DESC LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);

$weather = "http://domain.com/update.php?ID=username&PASSWORD=password&dateutc=" . $row['date'] . "&tempf=" . $row['airt_f_avg'] . "&winddir=" . $row['winddir'] . "&windspeedmph=" . $row['ws_mph'] . "&windgustmph=" . $row[''] . "&rainin=" . $row['rain_in_tot'] . "&baromin=" . $row[''] . "&dewptf=" . $row['dewpt_f_avg'] . "&humidity=" . $row['rh_avg'] . "&action=updateraw"; 

header('Location:' . $weather);

include 'closedb.php';

?>

 

Let me know if you see any error in the code, if it looks good!

 

Thanks!!!

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.