PHP - Quick Help
what does
Code: [Select] WHERE p.pid IN(0,4561,0) mean? I know it's lokoing for DATA FROM p.pid = 4561, but WHAT THE HELL DOES THE 0, ,0 mean? Thanks Similar TutorialsI've made my first object that will addition an array but it doens't seem to be working as it echo's out 0. here is my script <?php class A { public $sum = 0; function addition($values){ foreach ($values as $numbers){ $this->sum = $number + $this->sum; } echo $this->sum; } } $a = new A(); $array = array(10, 15, 25); echo $a->addition($array); ?> I don't see what I'm doing wrong. Any direction would be greatly appreciated. i need some quick help, this project has been way over due and ive wasted huge amounts of time researching on my own and bothering others trying to figure this out and i just cant leave it be its like a damn drug. im desperate folks! my 2 tables, movies: id - title - category - url categories: id - category (FK) what im trying to do is have every category list as a table and then list the movies owned by that category in them, example: Category 1 --------------- title title Category 2 -------------- title title Category 3 -------------- title title the code im using is Code: [Select] <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $result = mysql_query("SELECT a.ID, a.Title, b.Category, a.URL FROM Movies AS a JOIN Categories b ON a.Category = b.ID ORDER BY b.Category"); echo "<table border='1'> <tr> <th>Title</th> <th>Category</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td width='100'><a href='".$row['URL']."'>" . $row['Title'] . "</a></td>"; echo "<td width='150'>" . $row['Category'] . "</td>"; } echo "</table>"; $result2 = mysql_query("SELECT ID,Category FROM Categories"); while($row2 = mysql_fetch_array($result2)) { echo "<tr>"; echo "<td>" . $row2['Title'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> but obviously this code gives me a single table that lists all the titles with category next to them and then under the table it lists my categorys from left to right and its looks like Title Category --------------------- title1 Drama title2 Comedy title3 Horror title4 Thriller -------------------- DramaComedyHorrorThriller what exactly do i need to change to display the results i want ? btw dont hammer me on using 2 while loops, some tell me i need 2 and others say 2 is pointless. i myself have no clue! Hi! I want to be able to create a dynamic tournament bracket but not sure where to get started, right now all the template brackets have been hardcoded, i.e. http://teamx1.com/templates/64.html Can you someone put me in the right direction by using PHP to create and write this file? I want to be able to create 64 + brackets but hardcoding is a huge headache and mistakes easily done. Thanks all. Does storing multiple values in 1 database field with a varchar let's say set at 150, all separated by "|'s" so I don't have to create a field name for each one is it better performance wise or no? (storing 6-7 different |'s that will be outputted with a array ofc) ? Is there a way to only output the first, say, 30 words of a variable? I have a way to do it in mind, but seems like it's messy and not practical. Any suggestions? E.g: WITHOUT LIMIT: Welcome to my store. Would you like to buy something? We have really good noodles and fishes in doodle pools. WITH LIMIT: Welcome to my store. Would you like... Sort of like a short preview. What is the difference between these two lines Code: [Select] !isset($_POST[$requiredField]) and Code: [Select] !$_POST[$requiredField] Hi everyone, In the DB, I store dates as date("Y-m-d H:i:s") so it reads "2010-10-25 23:16:06" In a SQL query, I want to query all 2010 dates. I tried, WHERE date_created = '".date("Y")."', but no luck. What goes where date("Y") is? Thanks hi. when i get into some function manual and there is a note says. Quote This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. . is that meaning that after 5.3.0 version this function will not be supported? thanks , Mor. Hi, I've seen code like this multiple times, but I don't really know what it means. function funcName(&$something) { // whatever } What exactly does the "&" do before the variable? Does JavScript run ONLY if included in a php if/else statement ? Here is a quick example: 1 is not higher than 2, so the else statement will run. My question is, will the first javascript1 code run too, or it will follow the if/else statement in php ? if (1>2) { <javascript code1> } else { <javascript code2> } how to open a site with curl that has frames ? when ive tried it gives "your broswer does not support frames" ... code <?php //storecodefound.php v1.0 //purpose is to store the http refer and the code associated with the site to a db to be collected and verified by submitcode.php $code = $_GET['code']; $site = $_SERVER['HTTP_HOST']; //check to see if the code already present $connect = mysql_connect("localhost","root","") or die (mysql_error()); $check = mysql_query("SELECT code FROM hunter.codes WHERE code='$code'") or die (mysql_error()); $row = mysql_num_rows($check); echo "result of \$row is ".$row; echo "<br />"; if ($row = 0) { //insert into db cause it's not there mysql_query("INSERT INTO hunter.codes (id, code, site) VALUES ('','$code','$site')") or die (mysql_error()); } else { //echo it's already here echo "Code already found on server!"; } ?> my question is the result of $row is infact 0 and the if statement says if $row is 0 to insert into db and instead it's given me the code is already found? I am starting to learn PDO by re-writing one of my existing scripts. Do I still need to validate $_GET or does PDO do the work for me? Currently I am using: Code: [Select] $id = $_GET['id']; $sth = $dbh->prepare('DELETE FROM van_reservations WHERE id = :id'); $sth->bindParam(':id', $id, PDO::PARAM_INT); $sth->execute(); I used to validate by using this: Code: [Select] $id = isset($_GET['id']) && is_numeric($_GET['id'])?(int) $_GET['id']:0; hey! I have a site where I want to use multiple issets at the same time, like if I have four buttons and four issets: if(isset($_POST['one'])) { echo '<div class="example_box">one</div>'; } if(isset($_POST['two'])) { echo '<div class="example_box">two</div>'; } if(isset($_POST['three'])) { echo '<div class="example_box">three</div>'; } if(isset($_POST['four'])) { echo '<div class="example_box">four</div>'; } but for some reason it seems like only one isset can be activate at a time, is there any way to work this out or something :s? I've tried some variants of elseif stuff and such, but yeah, I'm pretty new at this stuff Hi all, I my hunt for better coding i thought i look at some opensource CMS systems and one thing I saw in the index.php of the joomla cms was this. define('JPATH_BASE', dirname(__FILE__) ); define( 'DS', DIRECTORY_SEPARATOR ); require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); Are they using DS to make it work on any platform instead of using a / or a \ ? Also they define JPATH_BASE, now they use dirname(__FILE__) for this. I read that __FILE__ tells from where the script is running. But in that same guide they gave as example dirname(dirname((__FILE__)) instead of only 1 time dirname() That was this website btw: http://www.phpguru.org/php-application-structure can anyone tell why i would use dirname 2 times and not 1 or 3 or 4? -edit: OK that last question don't needs an answer, i just put loads of dirname() around it and it seems it's moving up in the file system. Leaves my first still open How do i display an image from my directory?!? :S I don't mean to be lazy and just ask people on here, I have researched it online but can't seem to find a quick simple answer. Thanks People!! Which is better, option 1 or option 2?
Option 1:
$updated = "n";
if ($v1 == "y") {
Do something with $v1;
$udpated = "y";
}
if ($v2 == "y") {
Do something with $v2;
$updated = "y"
}
OR Option 2:
if ($v1 == "y" && $v2 == "y") {
Do something with $v1 and $v2;
$updated = "y";
} elseif ($v1 == "y" && $v2 == "n") {
Do something with $v1, but not $v2;
$updated = "y";
} elseif ($v1 == "n" && $v2 == "y") {
Do something with $v2, but not $v1;
$updated = "y";
} elseif ($v1 == "n" && $v2 == "n") {
Don't do anything with $v1 or $v2;
$updated = "n";
}
I've used both methods, and they both work, but I'm not sure which one is the best to use. Does if even really matter? Thanks for your opinion.
hey guys i have a script that creates a cookie named "MyLoginPage" now everything works well the cookie is saved and it keeps the user logged in The Question ok so im wanting to create a link that will delete the cookie so when the user clicks the link it will delete the cookie is this possible?? if so, how?? many thanks Hi I need someone to fix a bug I have and to "speed up" the loading of the image by having the firs x number of images load first then loading more after they finish.
The bug should be easy to fix as I have a working copy of the page minus the change I made. The problem is since I updated to code the other part wont work (
contact me for more details and let me know you how much you would charge.
Thanks,
.
I need to use a HTML form to retrieve data in a certain order of ascending/descending using a drop down box and a true/false statement button for one of the values from a MySQL database. Im guessing I need a php script to query the database, but can I add the php code to the HTML or upload a php to the server that links the HTML thank you |