HomeMonday, September 26, 2016, 22:24:41
3

MySQL Inner Join

Tuesday, February 10, 15, 09:58:34, 2 Yaers Ago Via wain, Hits: 1189
MySQL Inner Join - Creating Dynamic Webpages Using PHP and MySQL, Requirement(s): PHP Server, MySQL
Download source code:
http://phpform.net/download.php?f=inner_join.zip

config.php

Code:
<?php
//MySQL Configuration
//DB Host (Normally 'localhost')
$dbhost = 'localhost';
//DB Database Username
$dbusername = 'root';
//DB Database User Password
$dbpassword = 'mypassword';
//DB Database Name
$dbname = 'mydbname';
//mysql_connect function
$conn=mysql_connect($dbhost, $dbusername, $dbpassword);
if(!$conn) :
die('Could not connect: ' . mysql_error());
endif;
$db=mysql_select_db($dbname, $conn);
if(!$db) :
die ('Cant connect to database : ' . mysql_error());
endif;
?>


install.php

Code:
<?php
//make a MySQL connection
include('config.php');
//create a MySQL table in the selected database
mysql_query("CREATE TABLE `text` (
`textid` int(11) NOT NULL auto_increment,
`textvalue` text collate utf8_unicode_ci,
PRIMARY KEY (`textid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci AUTO_INCREMENT=1")
or die(mysql_error());
mysql_query("CREATE TABLE `numbers` (
`numberid` int(11) NOT NULL auto_increment,
`numbervalue` text collate utf8_unicode_ci,
PRIMARY KEY (`numberid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci AUTO_INCREMENT=1")
or die(mysql_error());
?>


index.php

Code:
<title>Index Page</title>
<center><h2>INDEX</h2></center><BR>
<?php
//make a MySQL connection
include('config.php');
echo "&nbsp;<a href=\"insert.php\">Insert PHP</a><br>";
//Get data from 2 tables
//*=select everything from table
$result = mysql_query("SELECT * FROM text
INNER JOIN numbers
ON numbers.numberid = text.textid")
or die(mysql_error());
while($link=mysql_fetch_array($result)){
//echo (display) a link using $link
echo $link['numbervalue'];
echo "-";
echo $link['textvalue'];
echo "<br>";
}
?>


insert.php

Code:
<title>Insert Page</title>
<center><h2>Insert Page</h2></center><BR>
<?php
//make a MySQL connection
include('config.php');
//to check if a submit button was clicked, use this...
if(isset($_POST['submit']))
{
$textvalue = $_POST['textvalue'];
$numbervalue = $_POST['numbervalue'];
//The INSERT INTO statement is used to add new records
//to a database table.
mysql_query("INSERT INTO text (textvalue)
VALUES ('$textvalue')")
or die(mysql_error());
mysql_query("INSERT INTO numbers (numbervalue)
VALUES ('$numbervalue')")
or die(mysql_error());
}else{
?>
<table><tr><td>
<form method="post" action="insert.php">
Textvalue:
</td><td>
<input name="textvalue" size="60" maxlength="255">
</td></tr>
<tr><td>
Numbervalue:
</td><td>
<input name="numbervalue" size="60" maxlength="255">
</td></tr>
<tr><td>
<input type="submit" name="submit" value="submit">
</form>
</td></tr></table>
<?php
}
?>

Sign In

Web Hosting
First Month Free with Coupon Code phpmonth
Unlimited Domains - Unlimited Storage
Unlimited Transfer - Unlimited Email
Related

Upload Image With PHP

[Example3] Tutorial - How to upload image in php.

Send This Link PHP Script

A popup form which allows your visitors to send a referral link from your site. It features admin notification and HTML output.

Site Recommendation

This script will allow your visitors to recommend your site to their friends.

Process Form Data with Jquery

jQuery, Process form data

PHP form with image upload

Advanced Contact Form with email and form field validation.It allows your visitors to send you an email directly from your website.Features: Image Upload, HTML Output, Captcha Image.

PHP Mail

Sends an email.

How to insert new line (IP Address) with fwrite

How to insert new line (IP Address) with fwrite, Get IP address and write to file.

PHP Fwrite : fwrite

php write to file - how to write data to a file using the php frwite function

Preg_Match - PHP Form Validation

PHP form validation with preg_match

Upload and Resize an Image with PHP

Tutorial - How to upload and resize image with PHP
About Author

wain

Date Registered: Sun, Feb 8, 15
Last Time Online: Sun, Sep 18, 16
So far has created 115 entries.
wain
This author has not yet filled in any details.