veedeoo 474 Junior Poster Featured Poster

you are very much welcome :).

veedeoo 474 Junior Poster Featured Poster

Hi,

I just borrowed this from someone...please see the script's credit on top. This might be more than what you need..if it just table names that you want, then just remove the bottom part of the script.

<?php
/****************
* File: displaytables.php
* Date: 1.13.2009
* Author: design1online.com
* Purpose: display all table structure for a specific database
****************/

//connection variables

$host = "localhost";
$database = "database";
$user = "user";
$pass = "password";

//connection to the database
mysql_connect($host, $user, $pass)
or die ('cannot connect to the database:' . mysql_error());

//select the database
mysql_select_db($database)
or die ('cannot select database:' . mysql_error());

//loop to show all the tables and fields
$loop = mysql_query("SHOW tables FROM $database")
or die ('cannot select tables');

while($row = mysql_fetch_array($loop))
{

echo "
<table cellpadding=2 cellspacing=2 border=0 width=75%>
<tr bgcolor=#666666>
<td colspan=5><center><b><font color=#FFFFFF>” . $row[0] . “</font></center></td>
</tr>
<tr>
<td>Field</td><td>Type</td><td>Key</td><td>Default</td><td>Extra</td>
</tr>";

$i = 0;

$loop2 = mysql_query("SHOW columns FROM " . $row[0])
or die ('cannot select table fields');

while ($row2 = mysql_fetch_array($loop2))
{
echo "<tr ";
if ($i % 2 == 0)
echo "bgcolor=#CCCCCC";
echo "><td>". $row2[0] . "</td><td>". $row2[1] . "</td><td>" . $row2[2] . "</td><td>" . $row2[3] . "</td><td>" . $row2[4] . "</td></tr>";
$i++;
}
echo "</table><br/><br/>";

}
?>
veedeoo 474 Junior Poster Featured Poster

I just noticed that if you give the script above a mirrored image strings,. the script will make the matched red :)

$phrase = "I made a program which prints hello World and hello world and helloworld and World Helloer.. Helloer World and helloworld and World hello prints which program  a made I.";
veedeoo 474 Junior Poster Featured Poster

ahaah! That's what I thought yesterday. My head was spinning, but I know for sure somewhere in the back of my head, I did this type of work before. It was one for the adult search functions. It will highlight the most possible matches..exact or from the fragments of words within the string.

kinda like this

<?php
$phrase = "I made a program which prints hello World and hello world and helloworld and World Helloer";
$words = "hEllO wOrLD";
## experimenting with strip_tags as shown ->http://www.w3schools.com/php/func_string_strip_tags.asp
$words = preg_replace('/\s\s+/', ' ', strip_tags(trim($words)));

$more_relevant = ''; ## not sure but may work, 
## $words = explode(' ',$words); ## this don't work codes are tired maybe :)
foreach(explode(' ', $words) as $word)
{
## testing if we can make the first match or more relevant to be red and bold
$first_match = '<b style="color:red;">'.$word.'</b>'; 
## this will be included in the echo which more precise matched
$more_relevant .= $first_match." ";

## matching all occurrences within string, exact or from fragments .
$phrase = str_ireplace($word, $first_match, $phrase);
}
## echo the $phrase in bold red in precise matched, and blue on the matched from fragments.
$phrase = str_ireplace(rtrim($more_relevant), '<b style="color:navy;">'.$words.'</b>', $phrase);

echo $phrase;
?>
veedeoo 474 Junior Poster Featured Poster

I learned how to write basic php programming when I was 13 ( was in high school). I read most if not all of the php tutorials in w3schools, read more about the functions I have learned from there in php.net. I cannot get enough and wanted to learn more, so I decided to go my local public library, and found an oriely book entitled Learning PHP, MySQL, and JavaScript 2009.

I learned a lot from oriely, and then At 16 yo, I moved on to tackle the smarty. There was a brief period were smarty was not updated anymore, it was struck of a luck I found DWOO templating system. After learning the DWOO, I found out that smarty is being updated and maintained once again, I went back to using smarty.

Now, at age 19 I am responsible in developing an open source youtube clone script, and many scrapers for adult and non-adults sites. Am I able to do all these things without the online learning environment? Probably not. In fact, this is the only time I finally had the time to join this community, even though I was already browsing questions and answers here for a long long time. I also learned a lot here.

What is really important I think is on how we are going to write the php application. I have seen some people who wrote their program to the extreme. Using many fancy functions and classes doing a much simpler …

veedeoo 474 Junior Poster Featured Poster

Hi,

Not sure if this is what you want. My reading comprehension is off at times, and today is one of those times. It's probably due to long working hours with a minimum pay :).

Codes below should give you the output "I made a program which prints Hello World"

<?php
$words = "hEllO wOrLD"; //the input (is usually always different each time)
$words = ucwords(mb_strtolower($words));
$phrase = "I made a program which prints Hello World";
$result = str_ireplace("$words", "<b>$words</b>", "$phrase"); //str_ireplace(search_for, replace_with, apply_to)
echo $result;
?>
veedeoo 474 Junior Poster Featured Poster

@davy_yg;

On your product_edit.php, this ./product_edit.php?id=<?=$data?>&mode=edit, should be extracted since that you are using $_REQUEST. This is the reason why you are not getting the 'id'.

Although I cannot see it on your codes, maybe my eyes are just really tired. However, I would try handling the "mode" first, because that is the one that brought you to the product_edit.php. So it should be something like this

if ($_REQUEST[mode]=='edit'){
extract ($_REQUEST);
//do something


echo $_REQUEST['id'];//will give us the valid id from the previous page.

}

That's the only way I could see where we can make sense out of 'id', after it has been extracted.

veedeoo 474 Junior Poster Featured Poster

i just want to add, if for some reason you need to know the count of media with specific extensions, then following codes can be use.

$flvcount = count(glob("".$video_loc. "*.flv"));
$mp4count = count(glob("".$video_loc. "*.mp4"));
echo $flvcount; 
echo $mp4count;

Just echo $flvcount to display how many flv inside the directory media.

Joe_hoskins commented: Very well written respnses and they work very well +0
veedeoo 474 Junior Poster Featured Poster

ok, say we have a directory called media. Let's put all the media in this directory. For the sake of this example we have flv, mp4 videos inside this directory. I am not sure if we can play mp3 with the same player for video. I have not tested this script, but if you can post your progress, I can probably help you further.

<!-- below is our target jwplayer -->
<script type='text/javascript' src='player/jwplayer.js'></script>
<div id="container"></div>
<script type="text/javascript">
  jwplayer("container").setup({
    autostart: true,
    flashplayer: "player/player.swf",
    height: 370,
    width: 720
  });
</script>
<?php
//lets create a simple function to take care of the files
function dirVideo($dir) {
$d = dir($dir); 
while (false!== ($file = $d->read())) 
{
$extension = substr($file, strrpos($file, '.')); 
if(($extension == ".flv") || ($extension ==".mp4"))
$videos[$file] = $file; 
}
$d->close(); 
asort($videos); 
return $videos; 
}

//we are done with the simple function, lets define our directory

$video_loc = "media"; //this is the location of the uploaded video
//put them in ul
echo "<ul>";
//lets use the simple function we have created above
$array = dirVideo($video_loc);
if($array !=null){
    foreach ($array as $key => $video) 
    {
// we need the filename without the extension for our link.
$link_name = substr($video, 0 , -4);
?>
<li>
<a href="#" onclick="jwplayer().load('<?=$key?>')"><?=$link_name?></a>
</li>

<?}}
else{
	echo "Video directory! is empty";
} 


?>

Warning! the above script will not read file with this type of file name mysummer.vacation.video.flv . The reason is that the script will pick up the first dot, making the file extension as .vacation.

That's …

veedeoo 474 Junior Poster Featured Poster

,and here is how you can sort the allowed extensions. This will be based on the codes presented above.

$username= "Member Name";
$filename = strtolower($_FILES['file']['name']);
//lets get the extension of uploaded image
$ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
//compare the uploaded extension to allowed extensions
$allowed_exts = array('jpg', 'gif', 'bmp', 'png');
if ((array_search($ext, $allowed_exts) !== FALSE)){
//do whatever you want here
 // can name the image file with the username of the uploader if you want
$filename = str_replace(" ", "-", $username).".".$ext;
//move the uploaded file with the username name
move_uploaded_file($_FILES['file']['tmp_name'], $path.$filename);
//insert to database

}
else{
echo "File extension NOt allowed";

}
veedeoo 474 Junior Poster Featured Poster

ddymacek was right, and you can also do it like so..

<input type="button" value="Edit" onClick="location = './product_edit.php?id=<?=$data['id_produk']?>&mode=edit'">