1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Strange charaters appreaing from function???

Discussion in 'PHP' started by rob7676, Dec 11, 2009.

  1. #1
    I've been looking at this for hours now and can't figure it out. I am trying a new way of writing my functions and now I have these strange characters appearing. Hopefully these will show for you.
    my function:
    function getAlbums() {
    		require 'database.php';
    		$q = "SELECT * FROM albums ORDER BY id ASC";
    		
    		$result = $mysqli->query($q) or die($mysqli_error($mysqli));
    		
    		if($result) {
    			while($row = $result->fetch_object()) {
    				$title = $row->title;
    				$id = $row->id;
    			
    				print '<li><h3><a href="album-view.php?id=' . $id . '">' . $title . '</a></h3></li>';
    			}
    		}
    	}
    PHP:
    database.php
    $db_server = "";
    	$db_user = "";
    	$db_pass = "";
    	$db_name = "";
    
    	$mysqli = new mysqli($db_server, $db_user, $db_pass, $db_name) or die(mysqli_error());
    PHP:
    Can anyone please help me?
     
    rob7676, Dec 11, 2009 IP
  2. einsteinsboi

    einsteinsboi Well-Known Member

    Messages:
    1,122
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    140
    #2
    Check your database collation.
     
    einsteinsboi, Dec 11, 2009 IP
  3. rob7676

    rob7676 Peon

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Type/Collation
    MyISAM/latin1_swedish_ci

    It was this by default. Dont really know what they mean, still new to all of this.
     
    rob7676, Dec 11, 2009 IP
  4. einsteinsboi

    einsteinsboi Well-Known Member

    Messages:
    1,122
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    140
    #4
    What does the data in your database look like? Screenshot?
    What is the exact output that you get on your page? Screenshot.

    The collation should work fine, or you could try changing it to utf-8 for internationalization.
     
    einsteinsboi, Dec 11, 2009 IP
    rob7676 likes this.
  5. rob7676

    rob7676 Peon

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    db[​IMG]
    table [​IMG]
    site [​IMG]
     
    rob7676, Dec 11, 2009 IP
  6. einsteinsboi

    einsteinsboi Well-Known Member

    Messages:
    1,122
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    140
    #6
    Ah, that seems like it would be probably be a problem with your HTML/CSS code, not your PHP function.
     
    einsteinsboi, Dec 11, 2009 IP
  7. rob7676

    rob7676 Peon

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    That was my first thought, but when I remove the php its going away. I just uploaded all files to a sub dir on the site so you could see the live,but have some error regarding the mysqli. Is it possible that its not supported by my hosting?

    Her is the output source for that section of html.
    <div id="gallery">
    						<ul class="gallery">
    							<li><h3><a href="album-view.php?id=1">First few days</a></h3></li><li><h3><a href="album-view.php?id=2">Around the House</a></h3></li><li><h3><a href="album-view.php?id=3">Bush Gardens</a></h3></li><li><h3><a href="album-view.php?id=4">The Zoo</a></h3></li><li><h3><a href="album-view.php?id=5">tmp</a></h3></li><li><h3><a href="album-view.php?id=6">test</a></h3></li><li><h3><a href="album-view.php?id=7">test album</a></h3></li><li><h3><a href="album-view.php?id=8">test album 2</a></h3></li><li><h3><a href="album-view.php?id=9">test album 2</a></h3></li><li><h3><a href="album-view.php?id=10">test album 3</a></h3></li><li><h3><a href="album-view.php?id=11">last album test</a></h3></li>						</ul>
    
    					</div>
    					<div class="" align="center">
    						|| 
    						  <a href="gallery-edit.php?task=add-album">Add an Album</a> | 
    						  <a href="gallery-edit.php?task=delete-album">Delete an Album</a> | 
    						  <a href="gallery-edit.php?task=add-image">Upload an Image</a> | 
    						  <a href="gallery-edit.php?task=delete-image">Delete an Image</a> 
    						|| 
    					</div>
    
    HTML:
    That symbol shows before the first li.
     
    rob7676, Dec 11, 2009 IP
  8. einsteinsboi

    einsteinsboi Well-Known Member

    Messages:
    1,122
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    140
    #8
    Hmm, it's definitely a character set issue. I found this on Google search:

    It probably has to do with the code editor you are using to write and save your PHP file. Are you using Notepad? Read this to get an idea how to solve the problem: http://www.killersites.com/forums/topic/265/i-bom-characters/

    Hope this helps!
     
    einsteinsboi, Dec 11, 2009 IP
  9. rob7676

    rob7676 Peon

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I will read this now. Thank you so much for your help.
     
    rob7676, Dec 11, 2009 IP
  10. einsteinsboi

    einsteinsboi Well-Known Member

    Messages:
    1,122
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    140
    #10
    No problem, hope you figure it out :) Let me know how you do.
     
    einsteinsboi, Dec 11, 2009 IP
  11. rob7676

    rob7676 Peon

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    The forum posts you referenced stated it was a common problem with notepad and to use notepad++. I have never used notepad to code in, I use dreamweaver, but just started using notepad++ when I started this site. They said to change it at the save as operation and it didn't have that option, so I opened the files in notepad and change the type to ANSI and the BOM symbols are gone. Hopefully I wont have to do it all the time. Thanks again for you help
     
    rob7676, Dec 11, 2009 IP
  12. einsteinsboi

    einsteinsboi Well-Known Member

    Messages:
    1,122
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    140
    #12
    Glad you were able to fix it. I generally use Notepad++, Eclipse PDT or Aptana IDE for coding PHP. Never had this issue so not too sure why you did.

    Anyway, in Notepad++, click on Format and ensure that "Encode in ANSI" is the option selected.

    Hopefully that will take care of future problems!
     
    einsteinsboi, Dec 11, 2009 IP