close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Creating a composite field

Thread began 7/06/2011 4:25 pm by john70964 | Last modified 7/13/2011 5:47 pm by john70964 | 3092 views | 11 replies |

john70964

Creating a composite field

Can anyone say how I create a composite field in mysql.

I have two fields, one defaults to the string images/ and the other contains the image name.

I wish to have a composite field images/imagename

I can use navicat if needed.

Many thanks
John

Sign in to reply to this post

Jason ByrnesWebAssist

the image path should be set by the database, it should be set on the page that will display the image since the path will be different based on the where the page is in the site in relation to the where the image is.


when you display the image, use the image columns from the recordset and add the path before it:

<img src="images/<?php echo $row_recordsetNmae['ColumnName']; ?>" />

Sign in to reply to this post

john70964

Thanks Jason,
Where you write"the image path should be set by the database" should this be
the image path should NOT be set by the database?

In the past when using access I could create a composite field in an access query. It seems this is not possible with MySQL?

Sign in to reply to this post

Jason ByrnesWebAssist

yes, sorry, it have read read:
the image path should NOT be set by the database

it _is_ possible to concatenate 2 fields in the query using the CONCAT() function:
sql-concat-in-mysql.aspx


but not recommended for what you are trying to accomplish

Sign in to reply to this post

john70964

Hello Jason
Thanks for the info regards the database.
I am trying to get a dynamic image to show but no luck so far.
I checked the image exists in c:\xampp\htdocs\FB_PHP\images The text fields show correctly.
I wonder if you can see if there is a mistake in the code at ['products.image190)']

I did insert a beginning (

I also tried it without the )
Bit it made no difference can you see any mistakes?


Regards
John


<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head>

<body>
<p>List Page</p>
<?php do { ?>
<p>&nbsp;&nbsp;&nbsp;<?php echo $row_rsProducts['image190']; ?>&nbsp;&nbsp;&nbsp;<?php echo $row_rsProducts['ProductName']; ?>
&nbsp;&nbsp;&nbsp;

<img src="images/<?php echo $row_rsProducts['products.image190)']; ?>"/></p>
<?php } while ($row_rsProducts = mysql_fetch_assoc($rsProducts)); ?>

</body>
</html>
<?php
mysql_free_result($rsProducts);
?>

Sign in to reply to this post

Jason ByrnesWebAssist

the image path is relative to the document.

using this source:
<img src="images/<?php echo $row_rsProducts['products.image190)']; ?>"/>


will only work if the document exists at the same level as the images folder, in other words if the images folder is at:
c:\xampp\htdocs\FB_PHP\images

that src path:
<img src="images/<?php echo $row_rsProducts['products.image190)']; ?>"/>

will only work if the document is in the FB_PHP folder
c:\xampp\htdocs\FB_PHP\


if not, you need to adjust the image path.

Sign in to reply to this post

john70964

The code seems OK but the images do not show.

Localhost seems OK please see image.
Perhaps you can see where I am wrong?
Thanks
John

Code is:

<?php require_once('Connections/Conn_FB_PHP.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$maxRows_rsProducts = 10;
$pageNum_rsProducts = 0;
if (isset($_GET['pageNum_rsProducts'])) {
$pageNum_rsProducts = $_GET['pageNum_rsProducts'];
}
$startRow_rsProducts = $pageNum_rsProducts * $maxRows_rsProducts;

mysql_select_db($database_Conn_FB_PHP, $Conn_FB_PHP);
$query_rsProducts = "SELECT * FROM concat_test WHERE ProductCategoryID = ProductCategoryID";
$query_limit_rsProducts = sprintf("%s LIMIT %d, %d", $query_rsProducts, $startRow_rsProducts, $maxRows_rsProducts);
$rsProducts = mysql_query($query_limit_rsProducts, $Conn_FB_PHP) or die(mysql_error());
$row_rsProducts = mysql_fetch_assoc($rsProducts);

if (isset($_GET['totalRows_rsProducts'])) {
$totalRows_rsProducts = $_GET['totalRows_rsProducts'];
} else {
$all_rsProducts = mysql_query($query_rsProducts);
$totalRows_rsProducts = mysql_num_rows($all_rsProducts);
}
$totalPages_rsProducts = ceil($totalRows_rsProducts/$maxRows_rsProducts)-1;
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>

<body>
<p>List Page</p>
<?php do { ?>
<p>&nbsp;&nbsp;&nbsp;<?php echo $row_rsProducts['image190']; ?>&nbsp;&nbsp;&nbsp;<?php echo $row_rsProducts['ProductName']; ?>
&nbsp;&nbsp;&nbsp;<img src="images/<?php echo $row_rsProducts['products.image190)']; ?>"/></p>
<?php } while ($row_rsProducts = mysql_fetch_assoc($rsProducts)); ?></body>
</html>
<?php
mysql_free_result($rsProducts);
?>

Sign in to reply to this post

john70964

It seems the imagename is not being found
source code in FF shows

<p>842|cav0022_190.jpg|Class Roberto Cavalli long black evening dress|
<img src="images/"/></p>
<p>953|cav0023_190.jpg|Class Roberto Cavalli black sequinned cocktail dress|
<img src="images/"/></p>

I edited the html code in FF and placed the image names in the correct position. The images showed OK
Please see pic attached.
I cannot see why the image does not show.

Sign in to reply to this post

Jason ByrnesWebAssist

the code that ios displaying the image name:
<?php echo $row_rsProducts['image190']; ?>

is not the same code you are using in the image src:
<?php echo $row_rsProducts['products.image190)']; ?>

the image tag:

<img src="images/<?php echo $row_rsProducts['products.image190)']; ?>"/>


should be changed to:
<img src="images/<?php echo $row_rsProducts['image190']; ?>"/>

Sign in to reply to this post

john70964

Thanks Jason
"should be changed to:
<img src="images/<?php echo $row_rsProducts['image190']; ?>"/>"

Yes I understand this now.

However it did not solve the problem
See image image190 Firebug
The images I believe are located correctly
See image190 Localhost
The recordset shows image190
See image Image190 recordset results.jpg
The ammended code is displayed in image190 1.jpg

Dreamweaver seems to run very slow in php could this be associated?

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...