//flex table opened by JP

Click to See Complete Forum and Search --> : mysql - dynamic links


phil drury
08-24-2005, 10:44 AM
Hi nice forum, right i have a problem im fairly new to mysql. I have built a searchable DB and i can display it in PHP the problem is the data it displays is only the shortened info. I need to add a link to display the rest of the row. For the life of me i cant work out / find out how to do it.

The link needs to know what row its on then display the row on a new page/pop up/ div tag.

i have a PRIMARY INDEX OF column Ref, The searchable fields are in a FULLTEXT index.


one more question! - How do you insert blocks of HTML into php or in an echo statement stop php from parseing punctuation?

Any help would be.................


Cheers Philo





function searchForm()
{
// Re-usable form

// variable setup for the form.
$searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');
$normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' );
$boolean = (($_GET['mode'] == 'boolean') ? ' selected="selected"' : '' );

echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">';
echo '<input type="hidden" name="cmd" value="search" />';
echo 'Search for: <input type="text" name="words" value="'.$searchwords.'" /> ';
echo 'Mode: ';
echo '<select name="mode">';
echo '<option value="normal"'.$normal.'>Normal</option>';
echo '<option value="boolean"'.$boolean.'>Boolean</option>';
echo '</select> ';
echo '<input type="submit" value="Search" />';
echo '</form>';
}


// Create the navigation switch
$cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : '');

switch($cmd)
{
default:
echo '<h1>Ice Promotions</h1>';
searchForm();

break;


case "search":
searchForm();
echo '<h3>Search Results:</h3><br />';

$searchstring = mysql_escape_string($_GET['words']);
switch($_GET['mode'])
{
case "normal":
$sql = "SELECT TownCity, CountyState, HotelName, WebsitePhotoPermission, GeneralDescription,
MATCH(TownCity, HotelName, CountyState, WebsitePhotoPermission, GeneralDescription)
AGAINST ('$searchstring') AS score FROM icepro
WHERE MATCH(HotelName, CountyState, TownCity, WebsitePhotoPermission, GeneralDescription)
AGAINST ('$searchstring') ORDER BY score DESC";
break;

case "boolean":
$sql = "SELECT TownCity, CountyState, HotelName, WebsitePhotoPermission, GeneralDescription,
MATCH(TownCity, HotelName, CountyState, WebsitePhotoPermission, GeneralDescription)
AGAINST ('$searchstring') AS score FROM icepro
WHERE MATCH(HotelName, CountyState, TownCity, WebsitePhotoPermission, GeneralDescription, )
AGAINST ('$searchstring') ORDER BY score DESC";
break;
}

$sql2 = $query = "SELECT * FROM icepro ";

// echo $sql;

$result = mysql_query($sql) or die (mysql_error());
$result2 = mysql_query($sql2) or die (mysql_error());
while($row = mysql_fetch_object($result))


{

echo '<div id="display"> <img src="'.stripslashes(htmlspecialchars($row->WebsitePhotoPermission)).'"> <strong> '.stripslashes(htmlspecialchars($row->HotelName)).'</strong><br /><br />';
echo '<strong> Town: </strong>'.stripslashes(htmlspecialchars($row->TownCity)).'<br />';
echo '<strong> Description: </strong>'.stripslashes(htmlspecialchars($row->GeneralDescription)).'<br />';
echo '<strong> Post Code: </strong>'.stripslashes(htmlspecialchars($row->Postcode)).'<br />';
echo '<strong> County: </strong>'.stripslashes(htmlspecialchars($row->CountyState)).'<br />';



// echo include ('display1.php');

echo '<form name="form1" method="GET" action="">';
echo '<input name="press" value="more..." type="button">';

echo '</form>';
echo '</div>';


}
break;
}



?>

</body>

JPnyc
08-24-2005, 10:05 PM
Which punctuation is it parsing? If it's ' or "" you have to escape each quote like this \".

JPnyc
08-24-2005, 10:19 PM
Another way would be just to use single ticks ' for all the html values, and double " around the entire statement to be echoed. I don't code PHP per se but that method works in other languages.

ScaryBinary
08-24-2005, 10:54 PM
Hi Phil, welcome aboard.

First, some linkage on PHP string handling....
How PHP handles strings, quotes, escape characters, etc. (http://www.php.net/manual/en/language.types.string.php)

The quoting style you used (single quotes surrounding your entire string) should work. I usually use double quotes, just because that's what I'm used to.

I'm not clear on what your question regarding the link is about. If you want to draw a link, just echo it like everything else:echo '<a href="details.php?ID=3">More Info</a>' ;

This will open a new page. Instead of passing in the value of "3" for the parameter "ID", you would pass in the primary key of the record whose data you want to display in the pop-up page. So you'd also need to grab your primary key from the database when you do your first query. Then your link might look like: echo '<a href="details.php?ID=' . $row->ID .'">More Info</a>' ;
..assuming "ID" is the name of your primary key (I think you said your primary key was "Ref"?). The "details.php" page would run another query, getting all the detailed information for the record identified by the primary key value you passed in the "ID" parameter.

Is that what you're asking? Or am I totally missing the mark? :D

phil drury
08-25-2005, 01:32 PM
Thanks, I will read that link and i think that was the exact bit of info i was looking for. Well it gave me a moment of inspiration anyway and when i have tried it out i will let you know!!!! When i have finnished the scripts i will post it on here if you like?!!

Cheers

phil drury
08-26-2005, 08:10 AM
Hey, am i correct in thinking that this is not passing the varible to the next page?

http://www.artaviaonline.co.uk/mysql/details.php?Ref=

i copied the

echo '<a href="details.php?Ref=' . $Ref->ID .'">More Info</a>' ;

phil drury
08-26-2005, 08:21 AM
Hey, am i correct in thinking that this is not passing the varible to the next page?

http://www.artaviaonline.co.uk/mysql/details.php?Ref=

i copied the

echo '<a href="details.php?Ref=' . $Ref->ID .'">More Info</a>' ;

but that is what i was after, just have to make it work and research how to recieve the varible and display it.



echo "<p><a href='#' onClick='MM_changeProp('more','','style.display',' block','DIV')'>show</a></p>"; i tried variouse methods above been one of them but not seem to work though it works fine in html. baffles me!

ScaryBinary
08-30-2005, 02:14 PM
I think you want something likeecho '<a href="details.php?Ref=' . $row->Ref .'">More Info</a>' ;

You need to use whatever variable/handle your SQL results are in. In your previous posts you were using things like$row->TownCity, so you want to reference your primary key in the same manner when you create your link. If "Ref" is your primary key column, and your PHP variable that stores the results of a mysql_query function is "$row" then what I have listed above should work.