cmgmyr
Members-
Posts
1,278 -
Joined
-
Last visited
Never
Everything posted by cmgmyr
-
true...you can also make different statements with putting the brackets in different places: if($a == 0 && ($b == 1 || $c == 3)){ echo "You did it"; } is not the same as: if(($a == 0 && $b == 1) || $c == 3){ echo "You did it"; }
-
yes, i think that was the only thing doing it. I think it's also good to enclose your statements in {}'s just incase your statement gets bigger later you won't have to worry about it. Like: <?php $d=date("D"); if ($d=="Fri"){ echo "Have a nice weekend!"; }elseif ($d=="Sun"){ echo "Have a nice Sunday!"; }else{ echo "Have a nice day!"; } ?> hope this helps
-
ok i think i got it, try : <?php $newsheads = get_news_id(); $i = 0; while($i < count($newsheads)){ //output newsheads echo $newsheads[$i]."<br />"; $i++; } function get_news_id() { $conn = db_connect(); $result = $conn->query("SELECT newshead FROM news ORDER BY id desc LIMIT 5"); if (!$result){ throw new Exception('Could not execute query'); } $i=0; while($row = mysqli_fetch_array($result)) { $newsheads[$i] = $row['newshead']; $i++; } return $newsheads; } ?>
-
what does your DB structure look like?
-
did you get an error or anything? what happened? ...also your hello needs to be echo "Hello";
-
try something like this: <?php $newsheads = get_news_id(); $i = 0; while($i < count($newsheads)){ //output newsheads echo $newsheads[$i]."<br />"; $i++; } function get_news_id() { $conn = db_connect(); $result = $conn->query("SELECT newshead FROM news ORDER BY id desc LIMIT 5"); if (!$result){ throw new Exception('Could not execute query'); } $i=0; while($row = mysqli_fetch_array($result)) { $return[$i] = $row['newshead']; $i++; } echo $return; } ?> ...i didn't test it, but it looks right let me know how it works out.
-
do you have an id associated with the record? if you do not you will have to make unique primary id's. also you can check this out: http://www.onlamp.com/pub/a/onlamp/2003/06/26/fulltext.html
-
or <?php if($var != 1){ //do something } ?>
-
also you can use this: <?php //go to page.php in 2 seconds echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=page.php\">"; ?>
-
Try this, it seemed to work for me. <?php if ($errors == "") { mysql_query("INSERT INTO registration2 VALUES( '', '".addslashes($_POST['firstname'])."', '".addslashes($_POST['lastname'])."', '".addslashes($_POST['email'])."' )") or die(mysql_error()); echo "Registration Successful!"; } else { echo $errors."Please go back and try again."; } //Here is the header code that doesn't: if ($errors == "") { mysql_query("INSERT INTO registration2 VALUES( '', '".addslashes($_POST['firstname'])."', '".addslashes($_POST['lastname'])."', '".addslashes($_POST['email'])."' )") or die(mysql_error()); header("Location: thankyou.php"); } else { echo $errors."Please go back and try again."; } ?> I pretty much just took out that exit;
-
try: <?php // Page ID $page="1"; ?> <?php require("db/connect.php"); // Already connected to mysql $query = "SELECT * FROM table WHERE id = $page"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $cnt = $row["count"]; $cnt++; } mysql_query( "UPDATE table SET count = $cnt WHERE id = $page"); // echo the number of htis echo $cnt; ?>
-
I'm assuming that your database will be getting bigger later so you should also think about looping through your query to show more lines of data.
-
[SOLVED] Mail form help please.. using existing user Db
cmgmyr replied to farkewie's topic in Third Party Scripts
Hey, maybe this will get you started. This is what I use for one of my sites. You can alter the sql query to send to only certain people, like type = 1. <?php global $db, $subject, $msg, $site_name, $site_email, $site_url; $result = mysql_query("SELECT * FROM users"); while ($row = mysql_fetch_array($result)){ $name = $row['name']; $email = $row['email']; $userid = $row['userid']; $message = "Hello $name,\n\n"; $message .= "$msg\n\n\n\n"; $message .= "-------------------------\n"; $message .= "$site_name\n"; $message .= "$site_url\n"; $to = $email; $header = "From: $site_name <$site_email>\n"; $header .= "Reply-To: $site_email\n\n"; if(mail($to, $subject, $message, $header)){ echo "Success sending to: $to (<a href=\"profile.php?userid=$userid\">$name</a>)<br>"; }else{ echo "<font color=\"#FF0000\">Error:</font> Failed sending to: $to (<a href=\"profile.php?userid=$userid\">$name</a>)<br>"; }//end else }//end while ?> let me know if you have any questions. -
can you list an example of what you would like to do? Maybe something like this: if($a == 0 && $b == 1 || $c == 3){ echo "You did it"; }
-
wow...you are amazing! thank you so much!
-
OK...so right now I have gotten all of the categories to display correctly with the current amount of products. I have found if the current category had children categories. Now what I want to do is make a list out of them. So that all categories are in the <li></li> tags, but if the catefory has children then add <ul>, then close the ul when all of the children for that parent are done. Currently I have the code outputting the begginning ul ok, but I can't seem to figure out how to close them all correctly, it's getting some of them...but not all. I have attached the small (test) database, the current (incorrect) output, and the correct output (that I manually altered). And here is the current script that I'm using: <?php session_start(); require "class.mysql.php"; $db = new mysql; listCats(0); session_destroy(); function listCats($id, $level=0) { global $db; $sql = "SELECT cat_id, cat_name FROM categories WHERE parent_id = '$id' ORDER BY cat_name"; $result = $db->query($sql); while (list($id, $name) = $db->fetchRow($result)) { $indent = str_repeat('-', $level*2); //See how many products this category has $products = "SELECT count(*) FROM products WHERE cat_id = '$id'"; $count_products = $db->fetchOneCol($products); if($count_products > 0){ $count_products = "($count_products)"; }else{ $count_products = ""; } //Get parent id $parent = "SELECT parent_id FROM categories WHERE cat_id = '$id'"; $parent_id = $db->fetchOneCol($parent); //See if there are any child catagories $child = "SELECT count(*) FROM categories WHERE parent_id = '$id'"; $count_child = $db->fetchOneCol($child); if($count_child > 0){ $end = "\n<ul>\n"; $show_child = $count_child; if(!$_SESSION[$id]){ $_SESSION[$id] = $count_child; } }else{ $end = ""; $show_child = "0"; if($_SESSION[$parent_id]){ $_SESSION[$parent_id]--; if($_SESSION[$parent_id] == 0){ $end = "\n</ul>\n"; } } } echo "$begin<li><a href=\"page.php?cat_id=$id\">$name</a></li>\n$end"; listCats($id, $level+1); } } ?> Thanks [attachment deleted by admin]
-
Simple enough Thanks again, I think that should be it for now.
-
Thanks! That worked great! Just one more thing... require "includes/class.mysql.php"; $db = new mysql; listCats(0); function listCats($id, $level=0) { global $db; $sql = "SELECT cat_id, cat_name FROM categories WHERE parent_id = '$id' ORDER BY cat_name"; $result = $db->query($sql); while (list($id, $name) = $db->fetchRow($result)) { $indent = str_repeat('-', $level*5); echo "$indent $id. $name<br />"; listCats($id, $level+1); } } Can I use anything other then global for $db? Thanks
-
Yes, I am using the parentid method. I'm just having a little trouble getting started. Here is what I have so far: $db = new mysql; $sql = "SELECT * FROM categories WHERE parent_id = 0 ORDER BY cat_name"; // Perform a query selecting five articles $result = $db->query($sql); // Display the results while ($row = $db->fetch($result)) { $cat_name = stripslashes($row['cat_name']); $cat_id = stripslashes($row['cat_id']); echo "$cat_name "; //See how many Sub-Categories there are $count = 0; //Clear count $sql = "SELECT * FROM categories WHERE parent_id = ".$cat_id; $sub = $db->query($sql); $count = $db->numRows($sub); if($count){ echo "($count) <br />"; //Continue to find more sub-categories }else{ echo "<br />"; } } Thanks
-
What is the best way to cycle through these categories and sub-categories? Thanks
-
Well the first thing that you need to do is close your content div like: <div id="header"></div> <div id="nav"></div> <div id="content"> <div id="box"> </div> </div> <div id="footer"></div> I'll assume that you are trying to center "box" right? If so you need to do this: #box{ width:200px; margin:0px auto; } and that should center it for you...you do need a width in there though. Hope that helps.
-
I'm not really fond of the network site. I think your PPA site has a lot more potential. The PPA site needs a little modification but I think it's doable. Your current network site just doesn't work, it looks pretty unprofessional and I think you will have a hard time attracting clients with it. Just my opinion
-
How much do you want to spend per month? How much space/bandwidth do you want/need? What features do you want? What's the matter with just buying a big shared hosting package?
-
I agree with ron...Why don't you keep the same site design as your main site? Usually if you make a "network" of sites they should all have the same flavor. I would say stay with your current main website design.
-
So I'm starting out in OOP and I decided to make my own little MySQL class. Can you please review and let me know if there is anything else i NEED either to make it better or for security. Will this be ok to use for a large site with lots of queries going on at the same time? Thanks mysql.php <?php $host = "localhost"; $username = "root"; $password = "password"; $database = "database"; // Connect to MySQL $connection = mysql_connect($host, $username, $password); // Select desired database $link = mysql_select_db($database, $connection); if (!$link) { die('Fatal Error: Could not connect to MySQL Database' . mysql_error()); } class mysql{ //Query MySQL Database function query($sql){ $result = mysql_query($sql); return $result; } //Fetch array Query MySQL Database function fetch($result) { $rows = mysql_fetch_array($result); return $rows; } //Count the number of rows in query function count_rows($result) { $count = mysql_num_rows($result); return $count; } } ?> test_mysql.php <?php // Include MySQL class require_once 'mysql.php'; // Instantiate MySQL class, connect to MySQL and select database $db = new mysql; $sql = "SELECT * FROM users WHERE type = 'f' ORDER BY name ASC"; // Perform a query selecting five articles $result = $db->query($sql); // Perform a count $count = $db->count_rows($result); echo "$count<br /><br />"; // Display the results while ($row = $db->fetch($result)) { $name = stripslashes($row['name']); echo "$name<br />"; } ?>