Jump to content

CrashOkami

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Everything posted by CrashOkami

  1. I got "undefined variable" and "index", and I wrote the code like this: <?php $pagenum = isset($_GET['pagenum']) ? intval($_GET['pagenum']) : 1; ?> Seems to be working now, can you please clarify that this is what you also did? Just to see if I got it right. Thanks a ton for your help
  2. It prints 30 records ($rows = mysql_num_rows($data); $page_rows = 30; ), but now I've set it to print as many as the database has ($page_rows = $rows;) until I fix this issue. I really can't seem to find it.
  3. That's great to know, thank you very much! True, I "had" no errors, I'll go edit the php.ini as you said. Thanks! EDIT: now it refreshes the page, renews the URL, but I'm still getting the results available for page 1 only. Maybe I should not limit the results to 30 the way I do?
  4. Hello once more, I'm having trouble with my pagination code. It's all going fine, queries and all, until the time that I have to change page. It just won't change, whether I hit Last or Next. <?php mysql_connect("##", "##","##") or die("Failed to connect."); mysql_select_db("##") or die("Failed to find database."); if (!(isset($pagenum))) { $pagenum = 1; } $data = mysql_query("SELECT * FROM news") or die("Could not execute query."); $rows = mysql_num_rows($data); $page_rows = 30; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM news $max") or die("Could not fetch query data."); while($info = mysql_fetch_array( $data_p )) { Print "<a href='news.php?News_ID=" .$info['News_ID']."'>"; Print $info['Title']; Print "</a>"; Print ", written at "; Print $info['Date']; echo "<br>"; } echo "<p>"; echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } echo " ---- "; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?> As it is, it fetches 30 results, and I have around 55 in my database. What's wrong when it comes to changing pages though? Can you help me sort this out? Thank you in advance!
  5. There's none for me, maybe because I'm a new user? I can't even mark your answer as an answer to the topic, which would be the same. Still, thanks for pointing that out!
  6. Silly, silly me. I've fixed it, and I'm pasting the code below case anyone stumbles upon this for help. { Print "<a href='news.php?News_ID=" .$info['News_ID']."'>"; Print $info['Title']; Print $info['Date']; Print "</a>"; echo "<br>"; } Moderators, please mark this as solved. Thank you!
  7. Hello, The code below is part of a pagination code, which is working perfectly until I put the <a href> code in it, so the results can be made links to the article in accordance. Problem is, I'm getting "undefined T_VARIABLE" on the first line of this. I know I've done a mistake with the quotes, for sure, but I can't seem to be able to fix it. { Print "<a href='news.php?News_ID="$info['News_ID'] " '>"; Print $info['Title']; Print $info['Date']; Print "</a>"; echo "<br>"; } I've used spaces where needed to make the quotes more easily visible. Thank you again!
  8. Yup, I meant that I need no programs etc, just alter the code, commands, functions and all that. Thanks for the clarification, though
  9. I can't thank you enough for all this, I will start the conversion process later. So, basically, wherever I spot a "MySQL", I change it to "MySQLi", and it's converted to MySQLi. Thank you again! I suggest the mods leave this open so if anyone finds the error in the above code posts the solution to it.
  10. Meh, still same, points me to the ELSE statement. Should I try rebuilding my whole database with MySQLi? Would it be worth it? At the very least, now would be the best time to do it, since it's empty of records, save for 1 admin account, and the tests which I'm always deleting.
  11. This is greatly appreciated, HDFilmMaker. Indeed, when my contract with this host ends (if not earlier), I will move on to a host with MySQLi. As noted under my profile picture, I'm a beginner, so I was unaware of this problem, and didn't bother searching for the differences between MySQL and MySQLi, so I didn't care if the host supported it or not. I'll try your code now and edit this post to let you know if it worked, thank you! EDIT: now it points me to the ELSE error: "Error, please fill in all the fields as needed. If the problem persists, contact the webmaster.", although I've filled in all the fields as needed :/
  12. I've uploaded my newest version of the site, but I found out I can't post any kind of text that has an apostrophe in it, which is impossible, since I'm writing full articles. I've read topics about "my_sql_real_string()", but I can't figure out how to implement it to my existing code. Plus, I have no means of transforming my MySQL database into a MySQLi at the moment. Since I get the error I've set to come when the query cannot be executed, I suppose this function has to be inside the query, right? So, can you please show me how to do it in the code below? <?php $Title = $_POST["Title"]; $Small_desc = $_POST["Small_desc"]; $Desc = $_POST["Desc"]; $Image = $_POST["Image"]; $Author = $_POST["Author"]; if(!$Title=="" && !$Small_desc=="" && !$Desc=="" && !$Image=="" && !$Author=="") { $db_name = "###"; $link = mysql_connect("###", "###","###") or die("There was an error connecting to the database."); $select_db = mysql_select_db($db_name, $link); $add_query="INSERT INTO news(News_ID, Title, Small_desc, Description, Image, Author, Date) values (NULL, '$Title', '$Small_desc', '$Desc', '$Image', '$Author', NOW())"; $add_results = mysql_query($add_query, $link) or die("Record not inserted. Could not execute query. Please try again. <br> <br>"); echo "Record successfully inserted. Go back to the <a href=admin_index.php>admin index page.</a>"; } else { echo "Error, please fill in all the fields as needed. If the problem persists, contact the webmaster."; } ?> Where ### = my database/host details. Thank you once again! Although on most of my topics, I figure it out before someone posts the solution, I believe this will not be the case here.
  13. That's a flood of information, I've bookmarked the topic for easy finding when in need of such tips. You guys are awesome, I asked for something trivial and I got a ton of tips
  14. Wow, although I got it to work, thank you for your detailed replies I will surely implement your code, since it looks (obviously) more professional than mine, and it looks it can give more/better results on errors, queries etc. Thank you PS: The parameter is indeed News_ID, my teacher always told me that it should always be lower-case, but I want everything to look tidy - I'm sure I'll change along the way, though, and use lower-case, as does the rest of the world
  15. Nevermind, mark this as solved. I was dumb enough to not define the variable atop the SQL code. Translated in code: <?php $id = $_GET["News_ID"]; ?> <?php mysql_connect("localhost", "root") or die("Failed to connect."); mysql_select_db("starblind_database") or die("Failed to find database."); $query = "SELECT * FROM news WHERE News_ID='$id'"; $result = mysql_query($query) or die("Failed to execute query."); while($row = mysql_fetch_array($result)) { $id = $_GET["News_ID"]; $title = $row["Title"]; $sdesc = $row["Small_desc"]; $author = $row["Author"]; $desc = $row["Description"]; $date = $row["Date"]; } ?> Thanks for stopping by anyway
  16. Haha yeh I thought someone would mention this
  17. Hello, I'm setting up a page, where I'll dynamically post news. I've gotten the template to work, but now, it's static, as it only gets the last result from the database table. On the index page's slider, if you click on the image, you get to the template. All this works fine, but my problem is that I can't get the $_GET function to work, so it prints the data owned by the clicked item (i.e., the clicked "News_ID"). My code in the news.php (template) page is this: <?php mysql_connect("localhost", "root") or die("Failed to connect."); mysql_select_db("starblind_database") or die("Failed to find database."); $query = "SELECT * FROM news WHERE News_ID='$id'"; $result = mysql_query($query) or die("Failed to execute query."); while($row = mysql_fetch_array($result)) { $title = $row["Title"]; $sdesc = $row["Small_desc"]; $desc = $row["Description"]; $author = $row["Author"]; $id = $_GET["News_ID"]; $date = $row["Date"]; } ?> Which is on top of the page, above all, since I also want the page's title to be dynamic. But, I get "Undefined variables" for every variable I set in the "While" brackets, save for $id = $_GET["News_ID"];. Can someone help me understand what is the problem? I'm a beginner in Php, and this is a huge project, I'm actually glad I got it this far. Do not necessarily fix the code, but just point me in the right direction - no one is here to do my work for me. What am I doing wrong? Thank you in advance!
  18. Nevermind, got it to work. It's prompting me to my news template now, all fields entered. In case anyone needs help with the matter, I'll post the correct code below: <li> <h3><?php echo "$slide_title[5]"; ?></h3> <span><?php echo "$slide_image[5]"; ?></span> <p><?php echo "$slide_sdesc[5]";?></p> <?php echo "<a href=news.php?News_ID=".$News_ID."> <img src=".$slide_image[5]." alt ='$slide_title[5]' width='125' height='75'> echo Read the article</a>";?> </li> Of course, it's using my variables, but they're easy to figure out. Also, please excuse my double post, I hope it's no problem. Cheers!
  19. I've an update on the code. I think I've figured out the php, but I get some (I believe) minor issues, which I can't figure out. 284. <?php echo "<a href=news.php?News_ID=".$News_ID.'> 285. <img src="'.$slide_image[5].'" alt ='$slide_title[5]' width='125' height='75'>"; 286. echo "'>Read the article</a>'";?> I've numbered the lines for a reason. I get error message: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\xampp\htdocs\starblindsite\index.php on line 285. Am I close to fixing this? Thanks!
  20. I'm sorry, I forgot to preview it and now I can't edit it to display it properly. Yes, in the structure you posted it, although that piece of code is not functioning for some reason. I've not included the LI in the php code, just the variables inside it. <li> <h3><?php echo "$slide_title[5]"; ?></h3> <span><?php echo "$slide_image[5]"; ?></span> <p><?php echo "$slide_sdesc[5]";?></p> <?php "<a href=\"news.php?News_ID=".$News_ID."\">Read the article</a>";?> <?php echo '<img src="'. $slide_image[5].'" alt ="$slide_title[5]" width="125" height="75"/>' ;?> </li> I need it to be like this, but change the last 2 lines (not including </li>), so that </a> is placed after the <img /> tag. I need to make the <img /> line a link to the article - of course, if there's any other method of doing it, it's absolutely welcome. I just can't think of one.
  21. Hello everyone. So I got an image slider which I want to display news with descriptions etc, and everything's fine, but I can't make the main image a link to the article, because I get mixed up with "echo". I'm a beginner, so I'm asking for your help The code is: <li> <h3><?php echo "$slide_title[5]"; ?></h3> <span><?php echo "$slide_image[5]"; ?></span> <p><?php echo "$slide_sdesc[5]";?></p> <?php "<a href=\"news.php?News_ID=".$News_ID."\">Read the article</a>";?> <?php echo '<img src="'. $slide_image[5].'" alt ="$slide_title[5]" width="125" height="75"/>' ;?> </li> As you see, everything is alright code-wise, but it doesn't work how it should. Because, where <a href> ends (@ Read the article </a>), is the wrong place to end. </a> should be placed just before the </li>, and after the "echo img" line of code. Meaning, it should look like this (it's wrong, I know, just to help you understand): <li> <h3><?php echo "$slide_title[5]"; ?></h3> <span><?php echo "$slide_image[5]"; ?></span> <p><?php echo "$slide_sdesc[5]";?></p> <?php "<a href=\"news.php?News_ID=".$News_ID."\">Read the article <?php echo '<img src="'. $slide_image[5].'" alt ="$slide_title[5]" width="125" height="75"/>' ;?> </a>";?> </li> Thank you for your help
  22. I just noticed I'm missing the $_GET code, meant to get my items from the database and display them. I've filled them in, and now the database code looks like this: <?php mysql_connect("localhost", "root") or die("Failed to connect."); mysql_select_db("starblind_database") or die("Failed to find database."); $query = "SELECT * FROM news ORDER BY Date LIMIT 6"; $result = mysql_query($query) or die("Failed to execute query."); $Title = $_GET["Title"]; $Small_desc = $_GET["Small_desc"]; $Image = $_GET["Image"]; while($row = mysql_fetch_array($result)) ... ... Although they get counted as undefined variables. What seems to be the biggest problem is that I can't find a way to enclose my slider's UL, LI etc in my php, and the code shows up broken.
  23. Hello everyone, I'm building a gaming news, reviews etc website for my last project at the university. Although, I'm a bit bummed right now, I'm stuck and can't figure out how to handle this. I've got a neat image slider on my index page, with 6 options, and I want it to display the following items from my MySQL's "news" table: Title (headline), Small_desc (small description), and the Image (the header image, which I configured the slider to auto-size). My slider's raw, working (although static) code is as follows: <ul id="slideshow"> <li> <h3>Headline 1</h3> <span>photos/assassins01.jpg</span> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ut urna. Mauris nulla. Donec nec mauris. Proin nulla dolor, bibendum et, dapibus in, euismod ut, felis.</p> <a href="#"><img src="photos/assassins01.jpg" alt="Thumbnail_1" width="125" height="75"/></a></li> </ul> <div id="wrapper"> <div id="fullsize"> <div id="imgprev" class="imgnav" title="Previous Image"></div> <div id="imglink"></div> <div id="imgnext" class="imgnav" title="Next Image"></div> <div id="image"></div> <div id="information"> <h3></h3> <p></p> </div> </div> <div id="thumbnails"> <div id="slideleft" title="Slide Left"></div> <div id="slidearea"> <div id="slider"></div> </div> <div id="slideright" title="Slide Right"></div> </div> </div> What I want to work on is the 6 versions of the first part. I will need to replace static items with variables from my database's table's items, and display them, meaning I will have to make it look like this: <li> <h3>$Title</h3> <span>$Image</span> $Small_desc <a href="my article"><$Image alt="$Title" width="125" height="75"/></a></li> Problem is, I'm getting lots of errors when I try to configure it myself. I've already connected to my database, and made the code ask for the last 6 items, sorted by Date. Code is as follows: <?php mysql_connect("localhost", "root") or die("Failed to connect."); mysql_select_db("starblind_database") or die("Failed to find database."); $query = "SELECT * FROM news ORDER BY Date LIMIT 6"; $result = mysql_query($query) or die("Failed to execute query."); while($row = mysql_fetch_array($result)) { [b]...[/b] } ?> In the bold part, my slider's code should be present. At this point, I've started working on my other pages and abandoned index, but I'm finishing the others, and want to finish the index one, as my project is due for this Tuesday. I'm kindly asking you all, can you please help me? Or at least point me in the right direction, where I can pick up from and continue? It would be very, very appreciated. Thank you, Christos [/code]
×
×
  • 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.