Jump to content

stuart.cole

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

stuart.cole's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I think what you are asking for is related to limiting the number of results you receive, for example if you have select * from Articles WHERE date >=7/3/08 LIMIT 0,1 - I've not called using this date format previously but I believe it should work. you would get a reply from the database with the results showing articles 5 and 6, the >= means it will show results where the date is equal to or greater than '7/3/08', and the LIMIT starts at result 0 (the first result) and carries on for 1 more. If you use the above method but call <=5 you will get items for Id 5 and below, and as long as you 'ORDER by date DESC' the query it should work for the items below.
  2. Hi, any help would be really appreciated! I am trying to dynamically create a menu with sub levels but my head is now really starting to hurt! I have 2 basic tables, one for Top Level menu items, then below this would be data from the other table based upon that as the parent. The structure of the menu is simple and uses CSS and Java - I have attached a small example below - <ul id="menu"> <!--Headline Item--><li class="sub">Products <ul> <!--Sub head Item--><li><a href="#nogo">Product 1</a></li> <li><a href="#nogo">Product 2</a></li> <li><a href="#nogo">Product 3</a></li> </ul> </li> </ul> My Issue is, that I want these to be able to populate from the database as I add new items to it - I can figure out how to do it using loads of calls to the database (1 per headline item). Is there a way of using PHP and MySQL to create the top Headline item, and then based on this create the sub menu - and then rinse and repeat until all available Top Level Items are used? This is as close as I have got so far ... <ul id="menu"> <? $query = "SELECT * FROM nav_parent, nav WHERE nav.parent=nav_parent.parent order by nav_parent.priority"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) print "<li class='sub'>".$row['parent']."<ul>"; { echo"<li><a href='".$row['link']."'>".$row['pagename']."</a></li>";} echo "</ul></li>"; ?> </ul>
  3. My apologies, the first answer actually held the key. Thankyou for your help JacobYaYa
  4. My pages are made up from multiple php files (have a look at http://www.moneysavingdeals.co.uk ) and the pages are made from the header, points file, login file, left, centre, right and footer. On the login part, the call is to process.php to action the logging in/out/changes etc and as each action happens it changes it's headers to redirect on completion of the action which works very well. To save members going through the process of finding the site they want cashback from again it would be ideal to reload the originating page - which works, mostly. The issue is it doesn't have the session information as it's been through process.php so calls for merchant ID and Category ID fail and it returns a blank page. I could write the session info calls into process.php into it but it would be a pain as this file has shown itelf to be quite fragile in the last - getting it to finish process.php and change it's header to 'back page' would be an easy answer as once logged in you would return to the previous page still logged in and able to do what was wanted from there, but I don't know if it's possible. Does this make sense? So the question I suppose is - can you do a header redirect to go back 1 page or not?
  5. Hmm, as the login calls process.php to log in / out / update etc this just seems to call up a blank page as process.php is calling itself but with no actions ... if that makes sense
  6. Hi, I have a nice little log in script for members of my site, and I can redirect on successful login to a specific page, but I am struggling to know what to do to get them back to the page they logged in from. To be more specific - the site uses multiple session variables to generage certain pages, just using if($retval){ header("Location: ".$session->referrer); ends with the right page, but without the session variables so therefore a problem. If I let this page load and then backpage it works fine as it is going to the previously loaded page with the variables intact. Simply put - is there a way to automate the process of forcing a backpage once another page has loaded? Thanks Stu
  7. I know this will be simple for many of you - but I have a challenge! Something to do with rushing things probably ... But ... I have written a CMS system to use on my own websites which inputs news from an online form, adds to DB etc ... but adding the news automatically is causing me a challenge at times. My text input fields, where the text is taken from press releases etc quite often have apostrope's (') in the text - but these seem to be causing a problem when it tries to add the info to the DB... the apostrophe's are taken as part of the input coding, rather than just part of the text. I've found a work around where I can change the ' to ` in word and re-paste and that works, but isn't the right way of doing it. So, is there a way to force it to read an apostrophe as text, rather than code? Code used below ... <table width="400"><H1> INSERT NEWS HERE:</H1><br /><br /> <form action="insert3.php" method="post"> <tr><td>Heading: </td><td><textarea name="heading" cols="40" rows="2"></textarea></td></tr> <tr><td>Subhead: </td><td><textarea name="subhead" cols="40" rows="2"></textarea></td></tr> <tr><td>Main: </td><td><textarea name="main" cols="40" rows="20"></textarea></td></tr> <tr><td>Weblink: </td><td><input size="30" maxlength="250" type="text" name="weblink" value="http://"></td></tr> <tr><td>Date: </td><td><input size="30" maxlength="250" type="text" name="date" value="2007-"></td></tr> <tr><td>Added by: </td><td><select name="added" size="3"> <OPTION VALUE="Laura Cleaver">Laura</OPTION> <OPTION VALUE="Stuart Cole">Stuart</OPTION> <OPTION VALUE="Louise Allatt">Louise</OPTION></select></td></tr> <tr><td>Approved to go live? </td><td><select name="approved" size="2"> <OPTION VALUE="Y">Yes</OPTION> <OPTION VALUE="N">No</OPTION></select></td></tr> <tr><td><input type="submit" name="submit" value="Add News"></td></tr> </form></table> Insert 3 is here... <?php $con = mysql_connect("localhost","USERNAME","PASSWORD"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("secureitonline_db1", $con); $sql="INSERT INTO News (Heading, Subhead, Main, Weblink, Date, Added, approved) VALUES ('$_POST[heading]','$_POST[subhead]','$_POST[main]','$_POST[weblink]','$_POST[date]','$_POST[added]','$_POST[approved]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "News Story Added!"; mysql_close($con) ?>
  8. I had exactly the same issue recently - If you read this post you can see the help I received - which I have now got working [url=http://www.phpfreaks.com/forums/index.php/topic,111288.0.html]Check out huggies answer...[/url]
  9. I need to limit the character count on a returned query from more than one row in the database, I can get it to limit the output for 1 row with the trunc function - but adding additional calls to the functions doesn;t seem to work - what is the best way to do it? I've tried what seems logical and have got stuck with the below which (obviously to those who understand it) doesn't work. Help please! [Code] <? $query  = "SELECT * FROM News ORDER BY Time DESC LIMIT 0, 1"; $result = mysql_query($query); function trunc($details, $max){    if (strlen($details) > $max){       $details = substr($details, 0, $max);       $i = strrpos($details," ");       $details = substr($details, 0, $i);       $details = $details."...";    }    return $details; } while($row = mysql_fetch_array($result, MYSQL_ASSOC)){    $main = trunc($row['Main'], 200);{    $heading = trunc($row['Heading'], 75);{    $subhead = trunc($row['Subhead'], 100); // You see the call here to the above function    echo <<<HTML    {$row['Date']}<br><a href="newsitem.php?id= {$row['Newsid']}">{$heading}</a><br>{$subhead}<br>{$main} HTML; } ?> [/code]
  10. On the same note ... What if I need to limit the character count more than once? If so, what is the best way to do it? I've tried what seems logical and have got stuck with the below which (obviously to those who understand it) doesn't work. Thoughts? [code] <? $query  = "SELECT * FROM News ORDER BY Time DESC LIMIT 0, 1"; $result = mysql_query($query); function trunc($details, $max){   if (strlen($details) > $max){       $details = substr($details, 0, $max);       $i = strrpos($details," ");       $details = substr($details, 0, $i);       $details = $details."...";   }   return $details; } while($row = mysql_fetch_array($result, MYSQL_ASSOC)){   $main = trunc($row['Main'], 200);{   $heading = trunc($row['Heading'], 75);{   $subhead = trunc($row['Subhead'], 100); // You see the call here to the above function   echo <<<HTML   {$row['Date']}<br><a href="newsitem.php?id= {$row['Newsid']}">{$heading}</a><br>{$subhead}<br>{$main} HTML; } ?></div> [/code]
  11. Hi again, I have an issue, and although I see quite a bit of information I think should help, it just doesn;t seem to make sense - hence posting here... I have set a form up to add news to a database - works. The data when entered even has the physical line breaks and formatting of the data being pasted into it... Retreiving the information works, showing it works - formatting it is doing my head in... Is there a way to call the info with the formatting as it was when added to the database? I'm using an echo request as shown below, and have tried adding nl2br but with no joy ... any idea's? [code]<table width="640px" class="style10"><td> <? $Newsid = $_GET['Newsid']; $query = "SELECT * FROM News WHERE Newsid='" . $Newsid . "'"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "<br><br><br><br>" . $row['Date'] . "<br><br>"  . $row['Heading'] . ""; echo "<br><br>" . $row['Subhead'] . "<br><br>" . $row['Main'] . "<p></p><p></p>";} ?></td></table>[/code]
  12. Thanks both. It was the limit numbers that were confusing me - the rest was done but with your plain example I can see how that works now. Much appreciated.
  13. Hi I am building a news delivery site - with the news being delivered in 3 areas. The first should have the latest news item, the second area the second most recent item, and the third area, latest stories 3-7. How can I get PHP to select the last item, next to last, and then 3-7 since the ID's of these items will change as new items are added all the time? I know there is probably a very simple answer to this - but I've not found one yet :(
  14. Thanks to you both - with the application example/advice it makes a lot more sense now - cheers Huggie! Some of us need our hands held through this horrible learning curve :)
  15. I'm sure what you put is fab - but I am a true noob! How would I integrate this with the code I already employ as stated above? I've tried placing this (and changing the $details to $Main - and $max to $200 which suit the table I am working from) and putting it where the last ;echo call is - with no joy - and then just running your script without any of mine - but that also doesn't work. Probably silly questions I know - but any advice? [quote author=vbnullchar link=topic=111054.msg449749#msg449749 date=1160478796] try this function trunc($details,$max) { if(strlen($details)>$max) {         $details = substr($details,0,$max);         $i = strrpos($details," ");         $details = substr($details,0,$i);         $details = $details."...";     }     return $details; } [/quote]
×
×
  • 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.