Jump to content

jwcsk8r

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Everything posted by jwcsk8r

  1. thanks artacus, i think im starting to better understand. and if nothing else works from here on out i learned the word tuple. I assigned a foreign key in table 2, and linked it to a primary key in table 1. Heres the SQL... TABLE 1 - CREATE TABLE `person` ( `id` varchar(11) NOT NULL default '', `firstname` varchar(20) NOT NULL default '', `from_where` varchar(20) NOT NULL default '', `total_votes` int(11) NOT NULL default '0', `total_value` varchar(11) NOT NULL default '0', `used_ips` longtext NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; ANd Table 2.. CREATE TABLE `comtbl` ( `postID` int(11) NOT NULL auto_increment, `posterNAME` text NOT NULL, `postTXT` text NOT NULL, `foreign_id_from_PERSON` varchar(11) NOT NULL default '', PRIMARY KEY (`postID`), KEY `foreign_id_from_PERSON` (`foreign_id_from_PERSON`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; with the constraints for the second table being... ALTER TABLE `comtbl` ADD CONSTRAINT `comtbl` FOREIGN KEY (`foreign_id_from_PERSON`) REFERENCES `person` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; ____________________________________________________ Ok, so what I would like to happen is for when someone posts a comment into table 2, it posts the 'id' from the table person into the 'foreign_id_from_person" in table 2. this way when I go to print it on the page i can say... mysql_query("SELECT * FROM comtbl WHERE foreign_id_from_PERSON='$row_id_from_table_person'") this way it only prints out comments related to the post at hand. Technically, I think it should be working but it is not. I keep getting this error.."Error adding entry: Cannot add or update a child row: a foreign key constraint fails". I've been reading for the last 2-3 hours how to fix it and i cant seem to get anything to work. Thanks again for any help!
  2. okay, after i set the primary and foreign keys what should i do? Should it automatically update in the tables? Do the amount of rows in each table have to be the same for this to work? (They are not) THanks again
  3. apologies...going to move this to sql part of the forum
  4. Hey everyone, I am going to try and explain what I am trying to do as clearly as possible but even I think I am a little confused. I have one table in a database that is essentially stuff from a commenting script. Things that are posted in it are name, timestamp, id, etc... After this I have another table in the same database that is like a comment system for the first database with id, name, time. How can I set it up so that comments from the second database are only shown if it matches the id from the first database that the person commented on.
  5. Hey everyone, I am going to try and explain what I am trying to do as clearly as possible but even I think I am a little confused. I have one table in a database that is essentially stuff from a commenting script. Things that are posted in it are name, timestamp, id, etc... After this I have another table in the same database that is like a comment system for the first database with id, name, time. How can I set it up so that comments from the second database are only shown if it matches the id from the first database that the person commented on.
  6. I have changed the code to... <?php if ($page != 0) { // Don't show back link if current page is first page. $back_page = $page - $limit; echo("<a href=\"multiple_pages.php?query=$query&page=$back_page&limit=$limit\">back</a> \n");} ?> but it still doesn't seem to be working??? I also tried turning Register_Globals to On in the php.ini file just to test it on the server and that didnt work either? I am so confused.
  7. When I run this locally using MAMP server, it works great. But when it is uploaded to my hosting company (hostmonster) it doesn't work at all. The navigation for the links using $PHP_SELF(I have also tried $_SERVER[’PHP_SELF’]) seems to be broken. What might be the issue? <?php if ($page != 0) { // Don't show back link if current page is first page. $back_page = $page - $limit; echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a> \n");} for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it. { $ppage = $limit*($i - 1); if ($ppage == $page){ echo("<b>$i</b>\n");} // If current page don't give link, just text. else{ echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a> \n");} } if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link. $next_page = $page + $limit; echo(" <a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a>");} ?> Here is a link also to the problem... http://jwcsk8r.com/iaredrunk/multiple_pages.php Much Thanks in advance!
  8. this works for me.... <?php function html2txt($document){ $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly '@<![\s\S]*?--[ \t\n\r]*>@', // Strip multi-line comments including CDATA ); $text = preg_replace($search, '', $document); return $text; } ?> and then use this.... $vdesc = html2txt($_POST[vendor_desc]);
  9. Hey everyone, any help is much appreciated. I have this basic php script that sort results from a database into 5,10,20,50 results a page and then divides the pages up into how many is required by the number of entries in the database...blablabla. Ok, so I run it on MAMP server on my computer and it works great and just as planned. But as soon as I upload it to my hosting company server it doesnt work at all. http://jwcsk8r.com/iaredrunk/multiple_pages.php. Now, the page recognizes the total number of entries and divides the required page links up properly it just seems to be the "navigation" isn't working. I really have no idea where the difference might be in the set-up (php.ini file, maybe?) or how to correct the issue. And both MAMP and my hosting company are running php4. I think it might have something to do with the register_globals or the server variables being called improperly. (i.e. $_SERVER["PHP_SELF"] and not $PHP_Self) but ive messed around with both and cant get it to work. Again, any help is much appreciated. __________________________________________ if (!($limit)){ $limit = 10;} // Default results per-page. if (!($page)){ $page = 0;} // Default page value. $numresults = mysql_query("SELECT * FROM person WHERE id LIKE '%". $query ."%'"); // the query. $numrows = mysql_num_rows($numresults); // Number of rows returned from above query. if ($numrows == 0){ echo("No results found matching your query - $query"); // bah, modify the "Not Found" error for your needs. exit();} $pages = intval($numrows/$limit); // Number of results pages. // $pages now contains int of pages, unless there is a remainder from division. if ($numrows % $limit) { $pages++;} // has remainder so add one page $current = ($page/$limit) + 1; // Current page number. if (($pages < 1) || ($pages == 0)) { $total = 1;} // If $pages is less than one or equal to 0, total pages is 1. else { $total = $pages;} // Else total pages is $pages value. $first = $page + 1; // The first result. if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) { $last = $page + $limit;} //If not last results page, last result equals $page plus $limit. else{ $last = $numrows;} // If last results page, last result equals total number of results. //escape from PHP mode. ?> <html> <head> <title>Search Results for <?=$query?></title> </head> <body> <center><h2>Search Results for <?=$query?></h2></center> <table width="100%" border="0"> <tr> <td width="50%" align="left"> Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b> </td> <td width="50%" align="right"> Page <b><?=$current?></b> of <b><?=$total?></b> </td> </tr> <tr> <td colspan="2" align="right"> </td> </tr> <tr> <td colspan="2" align="right"> Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5">5</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10">10</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20">20</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50">50</a> </td> </tr> </table> <? //Go back into PHP mode. // Now we can display results. $results = mysql_query("SELECT * FROM person WHERE id LIKE '%". $query ."%' ORDER BY timestamp DESC LIMIT $page, $limit"); while ($data = mysql_fetch_array($results)) { ?> <p><a href="<?=$data["id"]?>" title="<?=$data["id"]?>"><?=$data["firstname"]?></a> - <?=$data["lastname"]?></p> <? } ?> <p align="center"> <? if ($page != 0) { // Don't show back link if current page is first page. $back_page = $page - $limit; echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a> \n");} for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it. { $ppage = $limit*($i - 1); if ($ppage == $page){ echo("<b>$i</b>\n");} // If current page don't give link, just text. else{ echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a> \n");} } if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link. $next_page = $page + $limit; echo(" <a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a>");} ?>
×
×
  • 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.