
headmine
Members-
Posts
40 -
Joined
-
Last visited
Never
Everything posted by headmine
-
Exactly what I needed. I knew about spaces and a str_replace is exactly what I was going to do. Thanks so much for your help.
-
I have a string of Data. Inside this string there is a line of text that says Where: 1234 Main Street. What I would like to do is grab the address that comes after "Where:" and have the output with a link to google maps ex Where: <a href="http://maps.google.com?q=1234+Main+Street">1234 Main Street</a> Would I use preg_replace for this? Or am I attacking this the wrong way?
-
Ok. I got it. So here it is for anyone else that might run into this problem $sql = "SELECT value2, COUNT(value2) as total FROM mydb WHERE value1 = 'state' GROUP BY value2" foreach ($sql as $state) { echo $sql->meta_value . ' (' . $sql->total .')<br />'; } This would echo: state (count) CA (3323) NV (93) etc.
-
OK. I've gotten it this far. SELECT value1, COUNT(value2) FROM mydb WHERE value1 = 'state' GROUP BY value1" foreach ($v as $vn) { echo $vn->value1 . '<br />'; } This prints out each state listed . How do I get the numbers next to it? Any help would be appreciated!
-
OK! Breakthru! I was able to do this within the SQL database. SELECT value2, COUNT(value1) As total FROM mydb WHERE value1 = 'state' GROUP BY value2 When I do this in SQL it works beautifully! It breaks down the states and how many records there are for each. When I do this in php. I only get the first Value! =( How do I get it to display all the values? THANKS!
-
I have a database with 4 fields. Primary Key, Userid, Value1, Value2 Userid holds the User Id for the site. Value one is basically anything. It could be state, zip, phone etc. Value2 relates to Value1. I would like to make an sql query that would echo each UNIQUE Value2 and display a Count next to it which represents how many times it's duplicated. Example: CA(200) NY(300) TX(250) etc. Here's what I have so far. SELECT COUNT(DISTINCT value2) FROM mydb WHERE value1 = 'state' This returns 43 Which is probably correct because there are only 50 states in the U.S. Do I need a foreach loop? Please help. Thanks in Advance!
-
Sorry output is: <?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Headmine</title><description>Example of a RSS feed.</description><link>http://headmine.org</link><copyright>Copyright (C) 2009 headmine.org</copyright><item><enclosure length="1234567" type="image/jpeg" url="http://johnregalado.com/the-test/a-river-runs-though-it.jpg" /><url>http://headmine.org/the-test/a-river-runs-though-it.jpg</url></item><item><enclosure length="1234567" type="image/jpeg" url="http://johnregalado.com/the-test/mark-ruhi.jpg" /><url>http://headmine.org/the-test/mark-ruhi.jpg</url></item><item><enclosure length="1234567" type="image/jpeg" url="http://johnregalado.com/the-test/mark.jpg" /><url>http://headmine.org/the-test/mark.jpg</url></item><item><enclosure length="1234567" type="image/jpeg" url="http://johnregalado.com/the-test/namrok.jpg" /><url>http://headmine.org/the-test/namrok.jpg</url></item></channel></rss>
-
I've made a few edits.... Here is the link to the page: http://headmine.org/the-test/index.php I've only been able to get the icons to show with links. I'd like the images to display. here is the updated code <?php $channel = array("title" => "Headmine", "description" => "Example of a RSS feed.", "link" => "http://headmine.org", "copyright" => "Copyright (C) 2009 headmine.org"); foreach (glob("*.jpg") as $filename) { $items[] = array("img" => $filename); } $output = '<?xml version="1.0" encoding="ISO-8859-1"?>'; $output .= '<rss version="2.0">'; $output .= "<channel>"; $output .= "<title>" . $channel["title"] . "</title>"; $output .= "<description>" . $channel["description"] . "</description>"; $output .= "<link>" . $channel["link"] . "</link>"; $output .= "<copyright>" . $channel["copyright"] . "</copyright>"; foreach ($items as $item) { $output .= "<item>"; $output .= "<enclosure length=\"1234567\" type=\"image/jpeg\" url=\"http://johnregalado.com/the-test/". $item["img"] ."\" />"; $output .= "<url>http://headmine.org/the-test/". $item["img"] ."</url>"; $output .= "</item>"; } $output .= "</channel>"; $output .= "</rss>"; header("Content-Type: application/rss+xml; charset=utf-8"); echo $output; ?>
-
I don't understand? Like this foreach ($items as $item) { $output .= "<items>"; $output .= "<item>"; $output .= "<content><img src=\"http://LOCATION/" . $item["img_local"] . "\" /></content>"; $output .= "</item>"; $output .= "</items>"; }
-
When you view the file through a web browser it looks like a feed but no images show up. If I remove <img src= etc then the name of the files will appear. But as soon as I add img tags everything disappears.
-
What im trying to do is create a dynamic rss image feed based on images within a folder. Your array fix helped me but its . Still not working foreach (glob("*.jpg") as $filename) { $items[] = array("img_local" => $filename); } $output = '<?xml version="1.0" encoding="ISO-8859-1"?>'; $output .= '<rss version="2.0">'; $output .= "<channel>"; $output .= "<title>" . $channel["title"] . "</title>"; $output .= "<description>" . $channel["description"] . "</description>"; $output .= "<link>" . $channel["link"] . "</link>"; $output .= "<copyright>" . $channel["copyright"] . "</copyright>"; foreach ($items as $item) { $output .= "<item>"; $output .= "<content><img src=\"http://LOCATION/" . $item["img_local"] . "\" /></content>"; $output .= "</item>"; } $output .= "</channel>"; $output .= "</rss>"; header("Content-Type: application/rss+xml; charset=ISO-8859-1"); echo $output;
-
Is there an easier way to do this? I am trying to get create a dyamic array based on files within the folder. foreach (glob("*.jpg") as $filename) { $items = array("title" => $filename) } $output = '<?xml version="1.0" encoding="ISO-8859-1"?>'; $output .= '<rss version="2.0">'; $output .= "<channel>"; $output .= "<title>" . $channel["title"] . "</title>"; $output .= "<description>" . $channel["description"] . "</description>"; $output .= "<link>" . $channel["link"] . "</link>"; $output .= "<copyright>" . $channel["copyright"] . "</copyright>"; foreach ($items as $item) { $output .= "<item>"; $output .= "<title>" . $item["title"] . "</title>"; $output .= "</item>"; } $output .= "</channel>"; $output .= "</rss>"; header("Content-Type: application/rss+xml; charset=ISO-8859-1"); echo $output; ?> This doesn't even work correctly.
-
Never mind. I've asked about this before and just found my answer. Anyway to delete this?
-
Ok new problem... The form Needs to collect Company Name, and Contact Number(s). So Here is the form. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Insider Tips and Updates</title> <script> function addElement() { var ni = document.getElementById('myDiv'); var numi = document.getElementById('theValue'); var num = (document.getElementById('theValue').value -1)+ 2; numi.value = num; var newdiv = document.createElement('div'); var divIdName = 'my'+num+'Div'; newdiv.setAttribute('id',divIdName); newdiv.innerHTML = '<input name="aNumber[]" type="text" id="aNumber" size="12" /> <select name="aNumber[]"> <option value="Option">Option</option> <option value="Extension" selected="selected">Extension</option> </select> <input name="extOp[]" type="text" id="extOp" size="6" /><a href=\'#\' onclick=\'removeElement('+divIdName+')\'>Remove this number</a>'; ni.appendChild(newdiv); document.getElementByID('howMany').value = num; } function removeElement(divNum) { var d = document.getElementById('myDiv'); var olddiv = document.getElementById(divNum); d.removeChild(olddiv); } </script> </head> <body> <form id="form1" name="form1" method="post" action="process.php"> Company Name<br /> <label> <input name="company" type="text" id="company" /> </label><br /> Contact Numbers <br /> <div id="myDiv"></div> <label> <input type="submit" name="Submit" value="Submit"/> </label> </form> <input name="hidden" type="hidden" id="theValue" value="0" /> <p><a href="javascript:;" onclick="addElement();">Add contact number</a></p> <p> </p> <p> </p> </body> </html> If there is more than one contact number the user can click "ADD CONTACT NUMBER" and another dynamic field is added. There is an input for: Phone Number, Option for Extension/Option, and the Extension/Option Number. I added a drop down menu for the user to select weather they need an extension or option number. its named select[] So there are 3 different form variables being passed here. aNumber[], select[], and extOp[] So what I need the php script to do is create a string for each dynamic field that looks something like this $contact = aNumber[] . select[] . extOp[]; if there are more than one contact number then i'd like them to be added to $contact but seperated by comma's because they will be inserted into a database. So I tried $i = 0; foreach ($_POST["aNumber"] as $key) $i++; echo $i; $j = 0; while ($j<=$i) { $content = $_POST["aNumber"] . "," . $_POST["select"] . "," . $_POST["extOp"]; $j++; } echo $content; That didn't work. So I am stuck... Thanks in advance for any help
-
@mikr WOW! Thanks soo much for that! It does exactly what I need it to do! PERFECTION! and no I did not know about elements[] You've opened up a world of possibilities for me now! THANK YOU THANK YOU THANK YOU
-
This is driving me insane. Why does it remove ALL the commas? I only want it to remove the last character $string = substr($str, 0, -1); echo ($string); this echos a,b,c, $string = substr($str, 0, -2); echo ($string); this echos abc How do I only remove the last character?
-
@radi8 That didn't seem to do anything? @mikr What you did worked. But it duplicated 1 value this is how it printed out a,b,c,d,d d was not duplicated from the form so somewhere in the script it causes it to duplicate. Here is what I am running. foreach($_POST as $key => $value) if ($value == "Submit") { } else { if (strpos($key, "bp") !== false) { $theString = "$value,"; } #echo "$key: $value<br>"; echo $theString; } So it works! That's the first phase. But when inserting into the SQL database I need to remove that last "," how would I do that? I tried $newString = rtrim($theString, ","); echo ($newString); but that just removed ALL commas. Which I don't want.
-
Ok so I have a form that will dynamically add fields to insert more info. Here is the code for that. <form id="form1" name="form1" method="post" action="process.php"> Company Name<br /> <label> <input name="company" type="text" id="company" /> </label><br /> Bullet Points<br /> <div id="myDiv"></div> <label> <input type="submit" name="Submit" value="Submit"/> </label> </form> <input name="hidden" type="hidden" id="theValue" value="0" /> <p><a href="javascript:;" onclick="addElement();">Add bullet point</a></p> The Process.php file looks like this. foreach($_POST as $key => $value) if ($value == "Submit") { } else { if (strpos($key, "bp")) { $theString = "$value,"; } echo "$key: $value<br>"; echo $theString; } What I am trying to do is exclude submit as a value. The form key that is duplicated is bp followed by its number ex. bp1 = a bp2 = b bp3 = c etc I would like the values of only those keys to create a string. example $theString = "a,b,c"; I thought the above code would work. but it doesnt. What am I doing wrong? Also the idea behind this is to allow submission of a "Company Name" Once they enter the company name they can add bullet points to the form for the company. I figured the easiest way to do this is the above method since I never know how many bullet points will be needed. So the SQL statment would be something like "INSERT INTO company (uid, bulletPoints) VALUES('$uid', '$theString'" Am I going about this in the wrong way? Thanks in advanced for any help!
-
Here's a quick question.. Where can I read about how to condense my scripts? I got this entire thing working. Basically Page 1 displays all the images in the folder <?php $files = glob('images/*.jpg'); $count = 0; $counter = 0; foreach ($files as $file) { echo ($count % 4 == 0)? "<br/>" : ""; echo "<a href=\"img.php?file=$file&count=$counter\" /><img src=\"$file\" width=\"100\" style=\"border:1px solid #e96302;\" /></a>"; $count++; $counter++; } ?> Once you click on the image it will take you to a page to view the images. <div align="center"> <table width="425" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <?php if(empty($_GET['file'])) { header('Location:view.php'); } else { $ifile = $_GET['file']; $files = glob('images/*.jpg'); $count = $_GET['count']; $next = $count + 1; $prev = $count - 1; $taly = 0; foreach ($files as $file) { $taly++; } ?> <?php if($_GET['count'] == 0) { } else {?> <td width="22"><a href="<?php echo("img.php?file=$files[$prev]&count=$prev"); ?>"><img src='../../../img/prev.png' width='22' height='24' border="0" /></a></td> <?php }?> <td width="381"><div align="center"><a href="view.php"><img src='<?php echo $ifile; ?>' border="0" /></a></div></td> <td width="22"><?php if($_GET['count'] != $taly -1) { ?> <a href="<?php echo("img.php?file=$files[$next]&count=$next"); ?>"><img src='../../../img/next.png' width='22' height='24' border="0" /></a> <?php } } ?></td> </tr> </table> </div> Thanks to Crayon Violet the first code is nice and tight. The second code is sloppy i think. So are there any good articles on how to make scripts smaller?
-
Yes working great now! Thank you
-
Wow! Thanks crayon violet that didn't work at first but I made a few adjustments and it works perfect! Here is what I did $files = glob('images/*.jpg'); $count = 0; foreach ($files as $file) { echo ($count % 4 == 0)? "<br/>" : ""; $count++; echo "<a href=\"img.php?file=$file\" /><img src=\"$file\" width=\"100\" style=\"border:1px solid #e96302;\" /></a>"; } Basically just made $count = 0; and changed the path to the file because the way you had it printed out this way "/image/images/image.jpg" THANKS ALOT!
-
I found the problem Then problem was with this while($count <= $counter) { I switched it to while($count < $counter) { All errors are gone now. =) Thanks everyone for the help. Here is the final code for anyone reading along. <?php $count = 0; $counter = 0; $break = 0; $dir = opendir("images"); while (($file = readdir($dir)) !== false) { if(stristr($file, ".jpg")) { $name[$counter] = $file; $counter++; } } while($count < $counter) { echo "<a href=\"img.php?file=$name[$count]\" /><img src=\"images/$name[$count]\" width=\"100\" style=\"border:1px solid #e96302;\" /></a>"; $count++; $break++; if($break == 4) { echo '<br />'; $break = 0; } } closedir($dir); ?>
-
Thanks for the quick reply but that didn't do anything. It is still printing out the same error. Any other ideas?
-
Ok I included that in some changes I made to the script and that fixed the looping problem all images are displaying but now I am getting an error. Here is the code <?php $count = 0; $counter = 0; $break = 0; $dir = @ opendir("images"); while (($file = readdir($dir)) !== false) { if(stristr($file, ".jpg")) { $name[${"counter"}] = $file; $counter++; } } while($count <= $counter) { echo "<a href=\"img.php?file=$name[$count]\" /><img src=\"images/$name[$count]\" width=\"100\" style=\"border:1px solid #e96302;\" /></a>"; $count++; $break++; if($break == 4) { echo '<br />'; $break = 0; } } closedir($dir); ?> here is the error PHP Notice: Undefined offset: 15 in PATH\TO\FILE\view.php on line 26 PHP Notice: Undefined offset: 15 in PATH\TO\FILE\view.php on line 26 it prints out twice. Also I noticed that at the end something is coming up blank here is what the script is printing out <a href="img.php?file=Picture 108.jpg" /><img src="images/Picture 108.jpg" width="100" style="border:1px solid #e96302;" /></a><a href="img.php?file=Picture 119.jpg" /><img src="images/Picture 119.jpg" width="100" style="border:1px solid #e96302;" /></a><a href="img.php?file=Picture 120.jpg" /><img src="images/Picture 120.jpg" width="100" style="border:1px solid #e96302;" /></a><a href="img.php?file=Picture 136.jpg" /><img src="images/Picture 136.jpg" width="100" style="border:1px solid #e96302;" /></a><br /><a href="img.php?file=Picture 138.jpg" /><img src="images/Picture 138.jpg" width="100" style="border:1px solid #e96302;" /></a><a href="img.php?file=Picture 139.jpg" /><img src="images/Picture 139.jpg" width="100" style="border:1px solid #e96302;" /></a><a href="img.php?file=Picture 140.jpg" /><img src="images/Picture 140.jpg" width="100" style="border:1px solid #e96302;" /></a><a href="img.php?file=Picture 142.jpg" /><img src="images/Picture 142.jpg" width="100" style="border:1px solid #e96302;" /></a><br /><a href="img.php?file=Picture 143.jpg" /><img src="images/Picture 143.jpg" width="100" style="border:1px solid #e96302;" /></a><a href="img.php?file=Picture 144.jpg" /><img src="images/Picture 144.jpg" width="100" style="border:1px solid #e96302;" /></a><a href="img.php?file=Picture 145.jpg" /><img src="images/Picture 145.jpg" width="100" style="border:1px solid #e96302;" /></a><a href="img.php?file=Picture 146.jpg" /><img src="images/Picture 146.jpg" width="100" style="border:1px solid #e96302;" /></a><br /><a href="img.php?file=Picture 147.jpg" /><img src="images/Picture 147.jpg" width="100" style="border:1px solid #e96302;" /></a><a href="img.php?file=Picture 148.jpg" /><img src="images/Picture 148.jpg" width="100" style="border:1px solid #e96302;" /></a><a href="img.php?file=Picture 149.jpg" /><img src="images/Picture 149.jpg" width="100" style="border:1px solid #e96302;" /></a><a href="img.php?file=" /><img src="images/" width="100" style="border:1px solid #e96302;" /></a><br /> Any help is appreciated.
-
I am trying to build my own gallery that reads the files from a folder. What I Need it to do is Choose only jpgs from the folder. Display 4 jpgs in a row the insert a line break to display the next for images Here is the code I have so far and it only displays one image over and over again and will not stop looping. <?php $count = 0; $counter = 0; $dir = @ opendir("images"); while (($file = readdir($dir)) !== false) { if(strpos($file, ".jpg")) { $name[${$counter}] = $file; $counter++; } } while($count <= $counter) { echo "<a href='img.php?file=". $name[${$count}]" /><img src='images/" . $name[${$count}] . "' width='100' style='border:1px solid #e96302;' /></a>"; $count++; if($count == 4) { echo '<br />'; $count = 1; } } closedir($dir); ?> im pretty sure the problem lies within the array. $name[${$counter}] = $file; Or has something to do with the $counter variable inside the name array. Please help! Thanks in advance