sasa
Staff Alumni-
Posts
2,804 -
Joined
-
Last visited
-
Days Won
1
Everything posted by sasa
-
try <?php $data = "1:USA:2,2:UK:2,5:LONDON:2"; foreach (explode(',', $data) as $a) { $b = explode(';',$a); $finalOutput[$a[0]]=array ( 'productID'=>$a[0], 'productCountry'=>$a[1], 'deliveryOption'=>$a[2] ); } if (array_key_exists(2,$finalOutput)) echo 'yes'; else echo 'no'; ?>
-
creating a variable from another variables value
sasa replied to chiefrokka's topic in PHP Coding Help
YES -
creating a variable from another variables value
sasa replied to chiefrokka's topic in PHP Coding Help
Try $VariableName = 'Week'.$Current_Week.'_Q1_Winner'; $$VariableName = $row['Name']; mysql_query("UPDATE `Winners` SET `$VariableName` = '".$$VaiableName."' Where `Year` = '2008' ") or die(mysql_error()); -
try <?php $con = mysql_connect("localhost","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("databsae", $con); $file = 'source.txt'; $start = '!CLIENTS:'; $end = ';'; # Put file to an array $lines = file( $file ); # Set up placeholders $loop = TRUE; $capture = FALSE; $filtered = array(); # Loop through lines, until we've found $end for( $i = 0, $count = count($lines); $i < $count && $loop === TRUE; $i++ ) { # Check to see if capturing has been turned on if ( $capture === TRUE ) { # Check to see if this is the endline if ( strpos($lines[$i], $end) === 0 ) # End the loop $loop = FALSE; else # Explode and add to filtered results // you don't need to do explode $filtered[] = trim($lines[$i]); } # Check to see if this is the starting line elseif ( strpos($lines[$i], $start) === 0 ) # Turn on capturing $capture = TRUE; } # Output results, use foreach loop(s) to build your query #print_r( $filtered ); #Start loop(s) for queries foreach( $filtered as $filter ) { // change $line to $filter and remove one extra VALUES (' $sql = "INSERT INTO `clients` (`id`, `callsign`, `cid`, `realname`, `clienttype`, `frequency`, `latitude`, `longitude`, `altitude`, `groundspeed`, `planned_aircraft`, `planned_tascruise`, `planned_depairport`, `planned_altitude`, `planned_destairport`, `server`, `protrevision`, `rating`, `transponder`, `facilitytype`, `visualrange`, `planned_revision`, `planned_flighttype`, `planned_deptime`, `planned_actdeptime`, `planned_hrsenroute`, `planned_minenroute`, `planned_hrsfuel`, `planned_minfuel`, `planned_altairport`, `planned_remarks`, `planned_route`, `planned_depairport_lat`, `planned_depairport_lon`, `planned_destairport_lat`, `planned_destairport_lon`, `atis_message`, `time_last_atis_recieved`, `time_logon`, `heading`, `QNH_iHg`, `QNH_Mb`) VALUES (NULL, '". str_replace(':', "', '",$filter)."');"; mysql_query($sql) or die(mysql_error()); } ?>
-
1st i have $file 2nd i get right part of it $part 3rd explode $part in lines and get array $lines 4th foreach($lines as $line){ naw in $line i get just one line of file with data and insert it in db }
-
put this in foreach loop
-
$sql = "INSERT INTO ... VALUES (NULL, '". str_replace(':', "', '",$line)."');"; mysql_query($sql) or die(mysql_error());
-
change lines $tags = tag_info(); $minimum_count = min(array_values($tags)); $maximum_count = max(array_values($tags)); to $tags = tag_info(); foreach ($tags as $t) $tags1[] = $t[0]; $minimum_count = min($tags1); $maximum_count = max($tags1);
-
now you have value1:value2:value3:value4 for inserting in db we need INSERT ... VALUES ('value1', 'value2', 'value3', 'value4') 1st part is constant for 2nd part you need to change : to ', ' and add (' to front and ') to end of string construct sql string and insert in db do this for each line
-
OK next step explode $lines with "\n"(new line)
-
channge $lines = file( $file ); to $lines = file_get_contents( $file );
-
try <?php $test = ';comments ; !STATS: A:B:C !SOMETHING: A:B:C !STATS: A:B:C'; $out = preg_match('/(?<=!SOMETHING:\n).*?(?=\n!STATS:)/s', $test, $a); echo $a[0]; ?>
-
try <?php function tag_info() { $result = m_q("SELECT * FROM pic_tags GROUP BY tag ORDER BY RAND() LIMIT 20"); while($row = mysql_fetch_array($result)) { // add both data to returned array $arr[$row['tag']] = array($row['count'], $row['description']); } ksort($arr); return $arr; } function tag_cloud() { $min_size = 10; $max_size = 30; $tags = tag_info(); $minimum_count = min(array_values($tags)); $maximum_count = max(array_values($tags)); $spread = $maximum_count - $minimum_count; if($spread == 0) { $spread = 1; } $cloud_html = ''; $cloud_tags = array(); foreach ($tags as $tag => $count) { $size = $min_size + ($count - $minimum_count) * ($max_size - $min_size) / $spread; //change output to $count[0](count) and $count[](description) //add ending a tag $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' . '" class="tag_cloud" href="tagedphoto.php?tag=' . $tag . '"> returned a count of ' . $count[0] . ' title="' . $count[1] . '" ">' . htmlspecialchars(stripslashes($tag)) . '</a>'; } $cloud_html = join("\n", $cloud_tags) . "\n"; return $cloud_html; } ?> not tested
-
PHP MySQL Problem driving me mad - PLEASE help!!!!
sasa replied to daveeboi's topic in PHP Coding Help
are you shure that your path to file is OK try to use full path -
look $_SERVER variable http://www.php.net/manual/en/reserved.variables.server.php
-
& browser interpret as & and after that is show amp;
-
try <?php echo htmlspecialchars('&'); // result is: & ?>
-
remove ; in foreach line <html> <head> <body> <form action="form5.php" method="post"> <? $days= array (1=>'m','n','k'); echo '<select name="day">'; foreach ($days as $key => $value) //; <-- remove this {echo "<option value=\"$key\">$value</option>";} echo '</select>'; ?> </form> <body> <head> <html>
-
[SOLVED] Gathering personal message data; Echo it
sasa replied to EPCtech's topic in PHP Coding Help
can you echo $message before str_replace and post it here -
[SOLVED] Gathering personal message data; Echo it
sasa replied to EPCtech's topic in PHP Coding Help
change $message=$msg['message']; to $message=$row['message']; -
try <?php $text = '<span id=edit_text_2 class="edit"> OR <span class="edit" id="edit_text_2">'; $id = 'edit_text_2'; $match = '/<span [^>]*id=["\']?'.$id.'["\' ][^>]*>/is'; preg_match_all($match, $text, $out); print_r($out); ?>
-
<?php $string = "123;12;12;12;23;;;;142;321;1;132;212;;322"; $replace = ""; $find = preg_replace("~(?<=;~",$replace,$string); ?>
-
Problem with calling vairables in the middle of html
sasa replied to blargalarg's topic in PHP Coding Help
google for heredoc