Jump to content

DarkJamie

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

DarkJamie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I've solved the problem. For anyone looking to display "x" amount of characters of a query result, the following function works perfectly: Define your $text variable from your query results (in my case "content") $text=$row['content']; Set the number of characters by defining $length and the trailing characters (...) by defining $tail function snippet($text,$length=164,$tail="...") { $text = trim($text); $txtl = strlen($text); if($txtl > $length) { for($i=1;$text[$length-$i]!=" ";$i++) { if($i == $length) { return substr($text,0,$length) . $tail; } } $text = substr($text,0,$length-$i+1) . $tail; } return $text; } then to print the limited result: echo snippet($text);
  2. I am having trouble finding info on how to display a partial result from my sql query. I know what I'd like to do is really simple, but my search always results in how to paginate my query results rather than display the partial data with more link. I'd like it to display like this: Story Title - Date Entered words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here ...more I can display my results just fine, I would just like to place the partial story on my main page like this. If anyone can point me in the right direction so I can read up on it, I'd be greatful.
  3. wow, thank you for that explanation. I'll definitely be reading up on that and making changes as recommended. I'll mark this one solved since this problem requires rewriting my code. Thanks again for your help and quick replies.
  4. I see where you're going with that, but before the version change, I didn't need to set the $id value for it to work. I'm still trying to wrap my brain around that logic, but it worked fine. I was able to add entries, edit them, delete them, and list them in any fashion i wanted with just the code I had. Now I'm sure the version change shouldn't have made a difference, since nothing on my site is actually dependent on either version yet, but once I implemented the change, the add_entry, edit_entry, delete_entry and results by id all stopped working. Having given thought to this logic, I went back and switched BACK to php4 and everything is working again, so I guess my question should be, with something as simple as a query by ID, how will I need to rework the code to work in php5?
  5. I'm hoping there is a simple solution for this problem. Yesterday I upgraded from PHP4 to PHP 5, as I want to use ImageMagick for my photo gallery. Now that I've upgraded, my blog queries only partially work. The following are two snippets of code querying the same db. This is my list page. It displays a list of titles with entry dates. This page works perfectly, and displays everything correctly. <?php //Generate the query $query = "SELECT id, title, content, author, UNIX_TIMESTAMP(entry_date) as date FROM news ORDER BY date DESC LIMIT 3"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // get resultset as object if (mysql_num_rows($result) > 0) { while($send = mysql_fetch_object($result)) { // print details echo "<a href='r.php?id=$send->id'><b class='style2'>$send->title</b></a> "; ?> <font class="style3"> <?php echo date("g:i A - F j, Y", $send->date +7200); ?> </font><br> <?php echo "<font class='style7'><i>Written by: </i><b>$send->author</b> </font><br>"; echo "<br>"; echo nl2br($send->content); echo "<br><br>"; } } ?> This is my results page. When executed, this page returns no result and no error messages. <?php include("includes/dark_db_access.php"); db_login(); //Generate the query to display news content $query = "SELECT title, content, author, UNIX_TIMESTAMP(entry_date) as date FROM news WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // get resultset as object $send = mysql_fetch_object($result); // print details if($send) { echo "<b class='style2'>$send->title</b> "; ?> <font class="style3"> <?php echo date("g:i A - F j, Y", $send->date +7200); ?> </font> <?php echo "<br><i>Written by: </i><b>$send->author</b> "; echo "<br><br>"; echo nl2br($send->content); echo "<br><br><font size=2 color=red><a href=my_sent.php>Main menu.</a></font>"; } ?> Since both queries are written in the same syntax, and the php code to display them is the same, I can not figure out why the results page (by id) fails to display anything. Unfortunately, since I'm hosted with GoDaddy, their geniuses, in their infinite wisdom, thought it best that economy users not have access to error logs, so I can't check them. Altho my brain's logic keeps telling me that if the list page works, and the results page is written the same way, it should work too. Mind you, until I switched to php5 yesterday, all of my db queries were working perfectly. Any ideas would be greatly appreciated.
  6. exactly. I'm two hours ahead so +7200 seconds like so (for anyone wanting to know) echo date("g:i A - F j, Y", $send->date +7200);
  7. Thank you so much. That was it. I tried so many variations trying to get it to display right. Now all I have to do is adjust time zone for the two hour difference and I'm done.
  8. progress. Now I'm getting the unformatted UNIX timestamp, but when I changed the line to: echo $send->date("g:i A - F j, Y"); it returned Fatal error: Call to undefined function: date() in /r.php on line 204 so I'm not sure how to get the formatting right calling from the $send array.
  9. Thank you for your help in this. In order to be more clear with my naming convention, I have changed the "date" table name to "entry_date" in the db to avoid a conflict with the date function. Taking your recommendation, I've removed the included site_funct with it's date function and used UNIX_TIMESTAMP in my SQL call. Now I'm getting "0" (literally zero) rather than the entry date. No errors are generated My code is as follows: SQL table" `entry_date` datetime NOT NULL default '00-00-0000 00:00:00', My display PHP code: <? //Generate the query to display news content $query = "SELECT title, author, content AND UNIX_TIMESTAMP(entry_date) as date FROM news WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // get resultset as object $send = mysql_fetch_object($result); // print details if($send) { echo "<b class='style2'>$send->title</b> "; echo $send->date; echo "<br><i>Written by: </i><b>$send->author</b> "; echo "<br><br>"; echo nl2br($send->content); echo "<br><br><font size=2 color=red><a href=my_sent.php>Main menu.</a></font>"; } ?> Here is the SQL from the entry page: $query = "INSERT INTO news(id, title, content, author, entry_date) VALUES(0, '$title', '$content', '$author', NOW())";
  10. I have written a personal blog site based on a tutorial for such and it works great, except for one thing. The tutorial was written to store the date of each post in the db and return the month, day and year. It works how it is supposed to, but I would like to display the time of each post as well. Here is where it gets messed up. I suspect the writer of the tutorial left out the time due to this very problem. The date is being set properly, but the time for each entry is the same, which obviously can't be. This is the code that the tutorial provided for the function: function formatDate($val) { $arr = explode("-", $val); return date("d M Y", mktime(0,0,0, $arr[1], $arr[2], $arr[0])); } Here is the change that I made for formatting: function formatDate($val) { $arr = explode("-", $val); return date("g:i A - F j, Y", mktime($arr[1], $arr[1], $arr[1], $arr[1], $arr[2], $arr[0])); } the function is called upon like this: echo formatDate($send->date); the mysql table was set like this: `date` datetime NOT NULL default '00-00-0000 00:00:00', I have changed the numbers in each instance of $arr in the above function to see how they would effect the results. Regardless of what values I put in, the times would change, but each entry would display the same time, rather than their actual post times. (all entries posted at 2:02 AM - February 10, 2010) I could just go back to the default setting to display only the day/month/year, but as I learn more PHP, I want to use the date and time values to display a calendar picture with sprites rather than a textual time stamp. So my question is, what would be the best way to properly display the timestamp for each entry?
  11. Thank you Atkichin. Explode was exactly what I needed.
  12. that is awesome. I originally tried to use the $rid in my sql query, but could only get it to display the last checked product. I will definitely give this a go. Thanks for the fast reply.
  13. Hi folks. I'm back with another question on displaying array results. My problem is pretty simple, I just haven't been successful in executing it. I have a page that displays a list of products with checkboxes and prices. The checked items go into an array called "reports". The data is then passed to the selection page, where I wish to display each product description and price based on the ID values from the checkbox array. So what I am asking is how do I display the description and price of each product in the array (and then print a sum of their prices)? here is my code for the selection page. It is incomplets, as I have cleaned out my erroneous code. if (isset($_POST['reports'])) { foreach ($_POST['reports'] as $key => $rid) echo "<h2>Individual Reports</h2>"; echo "<h4>You've selected the following reports:</h4>"; while ($row=mysql_fetch_array($sql_result)) { $id = $row["id"]; $file_number=$row["file_number"]; $filename=$row["filename"]; $description=$row["description"]; $price=$row["price"]; $active=$row["active"]; echo "<table border=0>"; echo "<tr>"; echo "<td width=320px>$description</td>"; echo "<td><b>$price</b></td>"; echo "</tr>"; echo "</table>"; } echo "</table>"; }
×
×
  • 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.