Jump to content

mystic7

Members
  • Posts

    18
  • Joined

  • Last visited

Everything posted by mystic7

  1. Josh, I would just LOVE to be able to teach you how to play guitar. I wouldn't show you how to play the chords, that would be like stealing snippets of code. No, I would just tell you what the chords are to a song, and if you get it wrong, I won't tell you the right way, I'll just point out that you're doing it wrong. Then you'll know what it's like asking for advice from a stuck up "programmer" like you. Go ahead and delete my account. I'm sure there are more helpful forums out there. To the rest of you, I'm sorry. That you have to deal with a jerk like Josh.
  2. Every time I try to do something the "right" way I get code that doesn't work. Further research shows that this syntax or that has been "deprecated". In ASP If I wanted to show the time it was a simple snippet like time(now). In PHP it's a mini-script in itself. I'll get to the "proper way" of doing things eventually. Right now I'm just trying to make things work and going over the syntax so I can break my ASP shaped way of thinking. btw, I notice that not one of you really answered my question. You just gave me your opinions on how I "should" be doing it.
  3. I will consider that in the future. Right now I'm still taking baby steps.
  4. btw, I found a snippet of code and cut it down to where it only displays the time: date("g.i a", time()); but the time it shows is 4 hours ahead. Since the server is running off my computer I don't see why it's doing this.
  5. I can't believe this is such a hassle. Google searches bring back results on displaying time differences, calculating the amount of time, etc. but not the syntax for sending the current time in hour:minute am/pm format. Little help, please.
  6. Thanks for the tips. Like I said I literally just started learning PHP two days ago, so you'll have to forgive my lack of coding etiquette. Yes, you can mark this solved.
  7. So are you saying my If/Then statement would have worked if I'd used the == operator? Again, sorry for all the posts but I'm not allowed to edit my previous posts.
  8. Right, forgot about that. There's no equivilent in ASP for ==. Thanks for all your help!
  9. GOT IT! I had to alter your classes code a bit but I got it working: // Retrieve data from database $sql="SELECT * FROM $tbl_name ORDER BY id DESC LIMIT 2"; $result=mysql_query($sql); // Start looping rows in mysql database. $classes = array('post_box', 'post_box post_box_last'); // define div classes here $i = -1; // initiate counter to -1 while($rows=mysql_fetch_array($result)){ $divname = $classes[++$i]; // get the next class, ++$i will increment $i by 1 $mystring = $rows['message']; ?> <div class= "<? echo $divname; ?>"><img src="images/templatemo_image_01.jpg" alt="image" /> <div class="post_box_right"> <h2><? echo $rows['title']; ?></h2> <div class="post_meta"><strong>Date: </strong><strong><? echo $rows['dateday']; ?></strong> <? echo $rows['datemonth']; ?> <? echo $rows['dateyear']; ?>| <strong>Author: </strong><? echo $rows['name']; ?></div> <p><? echo substr($mystring, 0, 100); ?>...</p> <a href="blog_post.php?id=<? echo $rows['id']; ?>" class="more">Read more</a><br /> <div class="category">Category: <a href="#">Freebies</a>, <a href="#">Templates</a> | <a href="blog_post.php">244 comments</a></div> </div> <div class="cleaner"></div> </div> <?php // close while loop }
  10. Can anyone tell me what's wrong with my If...Else statement? My $count is changing from 1 to 2 but the value of "div" is not changing. // Start looping rows in mysql database. $count = 1; while($rows=mysql_fetch_array($result)){ $mystring = $rows['message']; If ($count = 1) { $div = ("post_box"); } Else { $div = ("post_box post_box_last"); } ?> <div class="<? echo $div; ?>"> <img src="images/templatemo_image_01.jpg" alt="image" /> <div class="post_box_right"> <h2><? echo $rows['title']; ?></h2> <div class="post_meta"><strong>Date: </strong><strong><? echo $rows['dateday']; ?></strong> <? echo $rows['datemonth']; ?> <? echo $rows['dateyear']; ?>| <strong>Author: </strong><? echo $rows['name']; ?></div> <p><? echo substr($mystring, 0, 100); ?>...</p> <a href="blog_post.php?id=<? echo $rows['id']; ?>" class="more">Read more</a><br /> <div class="category">Category: <a href="#">Freebies</a>, <a href="#">Templates</a> | <a href="blog_post.php">244 comments</a></div> </div> <?php // close while loop $count = $count + 1; }
  11. Looking at the page source I see that it's not actually changing the name of the div. I'm going to tweak the code a bit. I'll post back if I find a solution.
  12. Also (sorry, I'm not allowed to edit my posts yet) the div names were "post_box" and "post_box post_box_last", which I can't change using your method (it's a template I found, again, for the purpose of learning PHP, not web design). This is the code I used, which actually worked, but like I said, messed up other parts of the page layout: $count = 1; If ($count = 1) { $div = "post_box"; } Else { $div = "post_box post_box_last"; }
  13. Yes, that's exactly what I did, if slightly less elegantly But as I said, it messes up other CSS layout rules, so I'll leave it and concentrate on the PHP portion for now. I will, however, keep your code as a better way of implementing what I did with my usual half wit solution. Thanks!
  14. I did come up with a way to dynamically change the div name, and it did the trick, but the pages layout is not looking so great. Since my main point is to learn PHP I'm gonna let it go for now.
  15. EDIT: OK, I used a loop, and changed my SQL statement, and it does pull the last two posts and displays them, but the second one is not formatted nicely because it's going by the CSS rules for the first div. I'm going to try and come up with a way to dynamically change the name of the div with each loop in the meantime but if you have a better solution I'd love to hear it.
  16. Hey, thanks for responding. As I said this is just a fake blog that I'm using to get familiar with php syntax, so right now it doesn't matter if a row ID gets deleted. In fact that already happened so I just manually renumbered the recordsets in phpMyAdmin. If I may be so dense, could you explain, or point me to, directions on how to separate the entries using a loop? I know how to loop through recordsets in a database but I've never looped through recordsets after I've called for them. Again, if it's a normal looping procedure, how do I display the two recordsets inside two different divs?
  17. Hey, I'm just learning PHP. Used to be an ASP programmer so I'll have a lot of questions on how to do things in php that I used to do in ASP. Anyway, I am teaching myself by building a blog from an HTML template. Afterwards I'll study my code to really see what does what, proper syntax etc. On my home page there are two div's, each with different names but each containing the same information, i.e. a preview of a blog post. I have it so the two most recent posts show. The way I'm doing it is, I'm calling the top post with the following SQL statement: $sql="SELECT * FROM $tbl_name ORDER BY id DESC LIMIT 1"; I'm then displaying that post in the first div. For the second div, I'm retrieving the post previous to that with this SQL statement: $id = $rows['id']; $id2 = $id - 1; $sql="SELECT * FROM $tbl_name WHERE id = $id2"; This all works, but I'm wondering if there is a way to loop through the recordset and grab the two latest posts and then display them. The thing that's stopping me right now is the fact that the two posts are contained within two differently named divs. Or is my method acceptable as is?
×
×
  • 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.